Skip to content

Commit 00028e9

Browse files
committed
refactor(storage): 统一路径格式化逻辑并修复样式问题
移除 formatPathRclone 中的 isDir 参数,始终移除路径末尾斜杠 修复文件列表加载失败时的文本颜色问题
1 parent bab06c8 commit 00028e9

2 files changed

Lines changed: 10 additions & 14 deletions

File tree

src/controller/storage/storage.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ const convertStoragePath = (
226226
case 'rclone':
227227
return (
228228
(noStorageName ? '' : storageName + ':') +
229-
(onlyStorageName ? '' : path ? formatPathRclone(path, isDir) : '')
229+
(onlyStorageName ? '' : path ? formatPathRclone(path) : '')
230230
)
231231
case 'openlist': {
232232
// 修复双斜杠问题:确保 path 不以 / 开头再拼接
@@ -236,7 +236,7 @@ const convertStoragePath = (
236236
(onlyStorageName
237237
? ''
238238
: normalizedPath
239-
? formatPathRclone(storageName + '/' + normalizedPath, isDir)
239+
? formatPathRclone(storageName + '/' + normalizedPath)
240240
: storageName)
241241
)
242242
}
@@ -262,19 +262,14 @@ function getFileName(path: string): string {
262262
return pathArr[pathArr.length - 1] ?? ''
263263
}
264264

265-
function formatPathRclone(path: string, isDir?: boolean): string {
265+
function formatPathRclone(path: string): string {
266266
path = formatPath(path)
267267
if (path.startsWith('/')) {
268268
path = path.substring(1)
269269
}
270-
if (isDir) {
271-
if (!path.endsWith('/')) {
272-
path = path + '/'
273-
}
274-
} else {
275-
if (path.endsWith('/')) {
276-
path = path.substring(0, path.length - 1)
277-
}
270+
// 始终移除末尾斜杠
271+
if (path.endsWith('/')) {
272+
path = path.substring(0, path.length - 1)
278273
}
279274
return path
280275
}
@@ -284,9 +279,10 @@ async function getFileList(storageName: string, path: string): Promise<FileInfo[
284279
const storage = searchStorage(storageName)
285280
let fileList: FileInfo[] | undefined = undefined
286281

282+
// 移除路径末尾的斜杠,根目录直接传空字符串
287283
const backData = await rclone_api_post('/operations/list', {
288284
fs: convertStoragePath(storageName, undefined, undefined, undefined, true),
289-
remote: convertStoragePath(storageName, path, true, true),
285+
remote: convertStoragePath(storageName, path, false, true),
290286
})
291287

292288
if (backData && backData.list) {
@@ -295,7 +291,7 @@ async function getFileList(storageName: string, path: string): Promise<FileInfo[
295291
let filePath: string
296292

297293
if (storage?.framework === 'rclone') {
298-
filePath = formatPathRclone(file.Path, false)
294+
filePath = formatPathRclone(file.Path)
299295
} else {
300296
// OpenList 存储:从 file.Path 中提取相对路径
301297
// file.Path 格式可能是: 百度网盘/视频/test.mp4 或 /百度网盘/视频/test.mp4

src/page/storage/explorer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ function ExplorerItem() {
488488
})}
489489
/>
490490
) : (
491-
<div style={{ textAlign: 'center', marginTop: '10rem', width: '100%' }}>
491+
<div style={{ textAlign: 'center', marginTop: '10rem', width: '100%', color: 'var(--color-text-1)' }}>
492492
<div>
493493
{loading ? <Spin tip={t('filelist_loading')} /> : t('filelist_load_fail')}
494494
</div>

0 commit comments

Comments
 (0)