forked from akai/readest
fix: handle file basename from content provider uri (#861)
This commit is contained in:
@@ -157,11 +157,11 @@ export abstract class BaseAppService implements AppService {
|
||||
|
||||
try {
|
||||
if (typeof file === 'string') {
|
||||
filename = getFilename(file);
|
||||
fileobj = await this.fs.openFile(file, 'None');
|
||||
filename = fileobj.name || getFilename(file);
|
||||
} else {
|
||||
filename = file.name;
|
||||
fileobj = file;
|
||||
filename = file.name;
|
||||
}
|
||||
if (filename.endsWith('.txt')) {
|
||||
const txt2epub = new TxtToEpubConverter();
|
||||
@@ -210,10 +210,10 @@ export abstract class BaseAppService implements AppService {
|
||||
!transient &&
|
||||
(!(await this.fs.exists(getLocalBookFilename(book), 'Books')) || overwrite)
|
||||
) {
|
||||
if (typeof file === 'string' && isContentURI(file)) {
|
||||
await this.fs.copyFile(file, getLocalBookFilename(book), 'Books');
|
||||
} else if (filename.endsWith('.txt')) {
|
||||
if (filename.endsWith('.txt')) {
|
||||
await this.fs.writeFile(getLocalBookFilename(book), 'Books', fileobj);
|
||||
} else if (typeof file === 'string' && isContentURI(file)) {
|
||||
await this.fs.copyFile(file, getLocalBookFilename(book), 'Books');
|
||||
} else if (typeof file === 'string' && !isValidURL(file)) {
|
||||
await this.fs.copyFile(file, getLocalBookFilename(book), 'Books');
|
||||
} else {
|
||||
|
||||
@@ -14,7 +14,7 @@ import {
|
||||
} from '@tauri-apps/plugin-fs';
|
||||
import { convertFileSrc } from '@tauri-apps/api/core';
|
||||
import { open as openDialog } from '@tauri-apps/plugin-dialog';
|
||||
import { join, appDataDir, appCacheDir } from '@tauri-apps/api/path';
|
||||
import { join, basename, appDataDir, appCacheDir } from '@tauri-apps/api/path';
|
||||
import { type as osType } from '@tauri-apps/plugin-os';
|
||||
|
||||
import { Book } from '@/types/book';
|
||||
@@ -76,10 +76,11 @@ export const nativeFileSystem: FileSystem = {
|
||||
},
|
||||
async openFile(path: string, base: BaseDir, name?: string) {
|
||||
const { fp, baseDir } = resolvePath(path, base);
|
||||
const fname = name || getFilename(fp);
|
||||
let fname = name || getFilename(fp);
|
||||
if (isValidURL(path)) {
|
||||
return await new RemoteFile(path, name).open();
|
||||
return await new RemoteFile(path, fname).open();
|
||||
} else if (isContentURI(path)) {
|
||||
fname = await basename(path);
|
||||
if (path.includes('com.android.externalstorage')) {
|
||||
// If the URI is from shared internal storage (like /storage/emulated/0),
|
||||
// we can access it directly using the path — no need to copy.
|
||||
|
||||
Reference in New Issue
Block a user