(storageName: string, path: string)
| 276 | |
| 277 | //获取文件列表 |
| 278 | async function getFileList(storageName: string, path: string): Promise<FileInfo[] | undefined> { |
| 279 | const storage = searchStorage(storageName) |
| 280 | let fileList: FileInfo[] | undefined = undefined |
| 281 | |
| 282 | // 移除路径末尾的斜杠,根目录直接传空字符串 |
| 283 | const backData = await rclone_api_post('/operations/list', { |
| 284 | fs: convertStoragePath(storageName, undefined, undefined, undefined, true), |
| 285 | remote: convertStoragePath(storageName, path, false, true), |
| 286 | }) |
| 287 | |
| 288 | if (backData && backData.list) { |
| 289 | fileList = [] |
| 290 | for (const file of backData.list) { |
| 291 | let filePath: string |
| 292 | |
| 293 | if (storage?.framework === 'rclone') { |
| 294 | filePath = formatPathRclone(file.Path) |
| 295 | } else { |
| 296 | // OpenList 存储:从 file.Path 中提取相对路径 |
| 297 | // file.Path 格式可能是: 百度网盘/视频/test.mp4 或 /百度网盘/视频/test.mp4 |
| 298 | // 需要去掉存储名前缀,得到: 视频/test.mp4 |
| 299 | const rawPath = file.Path as string |
| 300 | const prefix = storageName + '/' |
| 301 | |
| 302 | if (rawPath.startsWith('/' + prefix)) { |
| 303 | // 格式: /百度网盘/视频/test.mp4 |
| 304 | filePath = rawPath.substring(prefix.length + 1) |
| 305 | } else if (rawPath.startsWith(prefix)) { |
| 306 | // 格式: 百度网盘/视频/test.mp4 |
| 307 | filePath = rawPath.substring(prefix.length) |
| 308 | } else { |
| 309 | // 兜底:直接使用原路径 |
| 310 | filePath = rawPath |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | fileList.push({ |
| 315 | path: filePath, |
| 316 | name: file.Name, |
| 317 | size: file.Size, |
| 318 | mimeType: file.MimeType, |
| 319 | modTime: new Date(file.ModTime), |
| 320 | isDir: file.IsDir, |
| 321 | }) |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | return fileList |
| 326 | } |
| 327 | |
| 328 | //删除文件 |
| 329 | type RefreshCallback = () => void |
no test coverage detected