(type: FileSystemType, params: any)
| 24 | |
| 25 | export default class FileSystemFactory { |
| 26 | static create(type: FileSystemType, params: any): Promise<FileSystem> { |
| 27 | let fs: FileSystem; |
| 28 | let options; |
| 29 | switch (type) { |
| 30 | case "zip": |
| 31 | fs = new ZipFileSystem(params); |
| 32 | break; |
| 33 | case "webdav": |
| 34 | /* |
| 35 | Auto = "auto", |
| 36 | Digest = "digest", // 需要避免密码直接传输 |
| 37 | None = "none", // 公开资源 / 自定义认证 |
| 38 | Password = "password", // 普通 WebDAV 服务,需要确保 HTTPS / Nextcloud 生产环境 |
| 39 | Token = "token" // OAuth2 / 现代云服务 / Nextcloud 生产环境 |
| 40 | */ |
| 41 | if (params.authType === "none") { |
| 42 | options = { |
| 43 | authType: params.authType, |
| 44 | } satisfies WebDAVClientOptions; |
| 45 | } else if (params.authType === "token") { |
| 46 | options = { |
| 47 | authType: params.authType, |
| 48 | token: { |
| 49 | token_type: "Bearer", |
| 50 | access_token: params.accessToken, |
| 51 | } satisfies OAuthToken, |
| 52 | } satisfies WebDAVClientOptions; |
| 53 | } else { |
| 54 | options = { |
| 55 | authType: params.authType || "auto", // UI 问题,有undefined机会。undefined等价于 password, 但此处用 webdav 本身的 auto 侦测算了 |
| 56 | username: params.username, |
| 57 | password: params.password, |
| 58 | } satisfies WebDAVClientOptions; |
| 59 | } |
| 60 | fs = WebDAVFileSystem.fromCredentials(params.url, options); |
| 61 | break; |
| 62 | case "baidu-netdsik": |
| 63 | fs = new BaiduFileSystem(); |
| 64 | break; |
| 65 | case "onedrive": |
| 66 | fs = new OneDriveFileSystem(); |
| 67 | break; |
| 68 | case "googledrive": |
| 69 | fs = new GoogleDriveFileSystem(); |
| 70 | break; |
| 71 | case "dropbox": |
| 72 | fs = new DropboxFileSystem(); |
| 73 | break; |
| 74 | case "s3": |
| 75 | fs = new S3FileSystem( |
| 76 | params.bucket, |
| 77 | params.region, |
| 78 | params.accessKeyId, |
| 79 | params.secretAccessKey, |
| 80 | params.endpoint |
| 81 | ); |
| 82 | break; |
| 83 | default: |
nothing calls this directly
no test coverage detected