fix: get correct filename when importing txt files on iOS (#1477)

This commit is contained in:
Huang Xin
2025-06-26 16:21:55 +08:00
committed by GitHub
parent 73878c14e3
commit 7bd1b03652
2 changed files with 6 additions and 2 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
import { EXTS } from '@/libs/document';
import { Book, BookConfig, BookProgress, WritingMode } from '@/types/book';
import { getUserLang, isContentURI, isValidURL, makeSafeFilename } from './misc';
import { getUserLang, isContentURI, isFileURI, isValidURL, makeSafeFilename } from './misc';
import { getStorageType } from './object';
import { getDirFromLanguage } from './rtl';
import { SUPPORTED_LANGS } from '@/services/constants';
@@ -34,7 +34,7 @@ export const isBookFile = (filename: string) => {
return Object.values(EXTS).includes(filename.split('.').pop()!);
};
export const getFilename = (fileOrUri: string) => {
if (isValidURL(fileOrUri) || isContentURI(fileOrUri)) {
if (isValidURL(fileOrUri) || isContentURI(fileOrUri) || isFileURI(fileOrUri)) {
fileOrUri = decodeURI(fileOrUri);
}
const normalizedPath = fileOrUri.replace(/\\/g, '/');
+4
View File
@@ -85,6 +85,10 @@ export const isContentURI = (uri: string) => {
return uri.startsWith('content://');
};
export const isFileURI = (uri: string) => {
return uri.startsWith('file://');
};
export const isValidURL = (url: string, allowedSchemes: string[] = ['http', 'https']) => {
try {
const { protocol } = new URL(url);