2025-01-03 00:12:15 +08:00
|
|
|
import { BaseHttpChallengeUploader } from "../api.js";
|
2025-01-04 01:45:24 +08:00
|
|
|
import { QiniuOssAccess, QiniuClient, QiniuAccess } from "@certd/plugin-lib";
|
2025-01-02 00:28:13 +08:00
|
|
|
|
2025-01-03 00:12:15 +08:00
|
|
|
export class QiniuOssHttpChallengeUploader extends BaseHttpChallengeUploader<QiniuOssAccess> {
|
2025-01-04 01:45:24 +08:00
|
|
|
async upload(filePath: string, fileContent: Buffer) {
|
|
|
|
|
const qiniuAccess = await this.ctx.accessService.getById<QiniuAccess>(this.access.accessId);
|
|
|
|
|
const client = new QiniuClient({
|
|
|
|
|
access: qiniuAccess,
|
|
|
|
|
logger: this.logger,
|
|
|
|
|
http: this.ctx.utils.http,
|
|
|
|
|
});
|
|
|
|
|
if (this.rootDir.endsWith("/")) {
|
|
|
|
|
this.rootDir = this.rootDir.slice(0, -1);
|
|
|
|
|
}
|
|
|
|
|
await client.uploadFile(this.access.bucket, this.rootDir + filePath, fileContent);
|
2025-01-02 00:28:13 +08:00
|
|
|
}
|
|
|
|
|
|
2025-01-04 01:45:24 +08:00
|
|
|
async remove(filePath: string) {
|
|
|
|
|
const qiniuAccess = await this.ctx.accessService.getById<QiniuAccess>(this.access.accessId);
|
|
|
|
|
const client = new QiniuClient({
|
|
|
|
|
access: qiniuAccess,
|
|
|
|
|
logger: this.logger,
|
|
|
|
|
http: this.ctx.utils.http,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (this.rootDir.endsWith("/")) {
|
|
|
|
|
this.rootDir = this.rootDir.slice(0, -1);
|
|
|
|
|
}
|
|
|
|
|
await client.removeFile(this.access.bucket, this.rootDir + filePath);
|
|
|
|
|
}
|
2025-01-02 00:28:13 +08:00
|
|
|
}
|