Skip to content

Commit

Permalink
✨ 打开备份目录 #182
Browse files Browse the repository at this point in the history
  • Loading branch information
CodFrm committed May 21, 2023
1 parent 27187a6 commit 7274e40
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 2 deletions.
8 changes: 8 additions & 0 deletions pkg/filesystem/baidu/baidu.ts
Expand Up @@ -138,4 +138,12 @@ export default class BaiduFileSystem implements FileSystem {
return list;
});
}

getDirUrl(): Promise<string> {
return Promise.resolve(
`https://pan.baidu.com/disk/main#/index?category=all&path=${encodeURIComponent(
this.path
)}`
);
}
}
2 changes: 2 additions & 0 deletions pkg/filesystem/filesystem.ts
Expand Up @@ -43,4 +43,6 @@ export default interface FileSystem {
delete(path: string): Promise<void>;
// 文件列表
list(): Promise<File[]>;
// getDirUrl 获取目录的url
getDirUrl(): Promise<string>;
}
4 changes: 4 additions & 0 deletions pkg/filesystem/onedrive/onedrive.ts
Expand Up @@ -142,4 +142,8 @@ export default class OneDriveFileSystem implements FileSystem {
return list;
});
}

getDirUrl(): Promise<string> {
throw new Error("Method not implemented.");
}
}
10 changes: 9 additions & 1 deletion pkg/filesystem/webdav/webdav.ts
Expand Up @@ -6,6 +6,8 @@ import { WebDAVFileReader, WebDAVFileWriter } from "./rw";
export default class WebDAVFileSystem implements FileSystem {
client: WebDAVClient;

url: string;

basePath: string = "/";

constructor(
Expand All @@ -17,7 +19,9 @@ export default class WebDAVFileSystem implements FileSystem {
if (typeof authType === "object") {
this.client = authType;
this.basePath = joinPath(url || "");
this.url = username!;
} else {
this.url = url!;
this.client = createClient(url!, {
authType,
username,
Expand All @@ -39,7 +43,7 @@ export default class WebDAVFileSystem implements FileSystem {

openDir(path: string): Promise<FileSystem> {
return Promise.resolve(
new WebDAVFileSystem(this.client, joinPath(this.basePath, path))
new WebDAVFileSystem(this.client, joinPath(this.basePath, path), this.url)
);
}

Expand Down Expand Up @@ -77,4 +81,8 @@ export default class WebDAVFileSystem implements FileSystem {
});
return Promise.resolve(ret);
}

getDirUrl(): Promise<string> {
return Promise.resolve(this.url + this.basePath);
}
}
4 changes: 4 additions & 0 deletions pkg/filesystem/zip/zip.ts
Expand Up @@ -61,4 +61,8 @@ export default class ZipFileSystem implements FileSystem {
});
return Promise.resolve(files);
}

getDirUrl(): Promise<string> {
throw new Error("Method not implemented.");
}
}
27 changes: 26 additions & 1 deletion src/pages/options/routes/Tools.tsx
Expand Up @@ -153,7 +153,32 @@ function Tools() {
/>
<Drawer
width={400}
title={<span>备份列表</span>}
title={
<div className="flex flex-row justify-between w-full gap-10">
<span>备份列表</span>
<Button
type="secondary"
size="mini"
onClick={async () => {
let fs = await FileSystemFactory.create(
fileSystemType,
fileSystemParams
);
try {
fs = await fs.openDir("ScriptCat");
const url = await fs.getDirUrl();
if (url) {
window.open(url, "_black");
}
} catch (e) {
Message.error(`获取备份目录链接失败: ${e}`);
}
}}
>
打开备份目录
</Button>
</div>
}
visible={backupFileList.length !== 0}
onOk={() => {
setBackupFileList([]);
Expand Down

0 comments on commit 7274e40

Please sign in to comment.