diff --git a/apps/readest-app/src/services/appService.ts b/apps/readest-app/src/services/appService.ts index 00fb521d..7702c250 100644 --- a/apps/readest-app/src/services/appService.ts +++ b/apps/readest-app/src/services/appService.ts @@ -270,13 +270,13 @@ export abstract class BaseAppService implements AppService { fileobj = file; filename = file.name; } - if (filename.endsWith('.txt')) { + if (/\.txt$/i.test(filename)) { const txt2epub = new TxtToEpubConverter(); ({ file: fileobj } = await txt2epub.convert({ file: fileobj })); } ({ book: loadedBook, format } = await new DocumentLoader(fileobj).open()); const metadataTitle = formatTitle(loadedBook.metadata.title); - if (!metadataTitle || !metadataTitle.trim()) { + if (!metadataTitle || !metadataTitle.trim() || metadataTitle === filename) { loadedBook.metadata.title = getBaseFilename(filename); } } catch (error) { @@ -326,7 +326,7 @@ export abstract class BaseAppService implements AppService { !transient && (!(await this.fs.exists(getLocalBookFilename(book), 'Books')) || overwrite) ) { - if (filename.endsWith('.txt')) { + if (/\.txt$/i.test(filename)) { await this.fs.writeFile(getLocalBookFilename(book), 'Books', fileobj); } else if (typeof file === 'string' && isContentURI(file)) { await this.fs.copyFile(file, getLocalBookFilename(book), 'Books'); diff --git a/apps/readest-app/src/services/nativeAppService.ts b/apps/readest-app/src/services/nativeAppService.ts index ea3892bd..eb6cb1dc 100644 --- a/apps/readest-app/src/services/nativeAppService.ts +++ b/apps/readest-app/src/services/nativeAppService.ts @@ -308,7 +308,7 @@ export const nativeFileSystem: FileSystem = { } } }; - await readDirRecursively(path, '', entries, fileList); + await readDirRecursively(fp, '', entries, fileList); return fileList; }, async exists(path: string, base: BaseDir) {