mirror of
https://github.com/certd/certd.git
synced 2026-04-23 11:37:23 +08:00
chore:
This commit is contained in:
@@ -1,24 +1,33 @@
|
||||
import { HttpChallengeUploadContext } from "./api";
|
||||
|
||||
export class HttpChallengeUploaderFactory {
|
||||
async getClassByType(type: string) {
|
||||
if (type === "alioss") {
|
||||
return (await import("./impls/alioss.js")).AliossHttpChallengeUploader;
|
||||
const module = await import("./impls/alioss.js");
|
||||
return module.AliossHttpChallengeUploader;
|
||||
} else if (type === "ssh") {
|
||||
return (await import("./impls/ssh.js")).SshHttpChallengeUploader;
|
||||
const module = await import("./impls/ssh.js");
|
||||
return module.SshHttpChallengeUploader;
|
||||
} else if (type === "ftp") {
|
||||
return (await import("./impls/ftp.js")).FtpHttpChallengeUploader;
|
||||
const module = await import("./impls/ftp.js");
|
||||
return module.FtpHttpChallengeUploader;
|
||||
} else if (type === "tencentcos") {
|
||||
return (await import("./impls/tencentcos.js")).TencentCosHttpChallengeUploader;
|
||||
const module = await import("./impls/tencentcos.js");
|
||||
return module.TencentCosHttpChallengeUploader;
|
||||
} else if (type === "qiniuoss") {
|
||||
return (await import("./impls/qiniuoss.js")).QiniuOssHttpChallengeUploader;
|
||||
const module = await import("./impls/qiniuoss.js");
|
||||
return module.QiniuOssHttpChallengeUploader;
|
||||
} else {
|
||||
throw new Error(`暂不支持此文件上传方式: ${type}`);
|
||||
}
|
||||
}
|
||||
createUploaderByType(type: string, opts: { rootDir: string; access: any }) {
|
||||
const cls = this.getClassByType(type);
|
||||
async createUploaderByType(type: string, opts: { rootDir: string; access: any; ctx: HttpChallengeUploadContext }) {
|
||||
const cls = await this.getClassByType(type);
|
||||
if (cls) {
|
||||
// @ts-ignore
|
||||
return new cls(opts);
|
||||
const instance = new cls(opts);
|
||||
await instance.setCtx(opts.ctx);
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user