2025-01-03 00:12:15 +08:00
|
|
|
import { BaseHttpChallengeUploader } from "../api.js";
|
2025-01-04 01:45:24 +08:00
|
|
|
import { TencentAccess, TencentCosAccess, TencentCosClient } from "@certd/plugin-lib";
|
2025-01-02 00:28:13 +08:00
|
|
|
|
2025-01-03 00:12:15 +08:00
|
|
|
export class TencentCosHttpChallengeUploader extends BaseHttpChallengeUploader<TencentCosAccess> {
|
2025-01-04 01:45:24 +08:00
|
|
|
async upload(filePath: string, fileContent: Buffer) {
|
|
|
|
|
const access = await this.ctx.accessService.getById<TencentAccess>(this.access.accessId);
|
|
|
|
|
const client = new TencentCosClient({
|
|
|
|
|
access: access,
|
|
|
|
|
logger: this.logger,
|
|
|
|
|
region: this.access.region,
|
|
|
|
|
bucket: this.access.bucket,
|
|
|
|
|
});
|
|
|
|
|
const key = this.rootDir + filePath;
|
|
|
|
|
await client.uploadFile(key, fileContent);
|
2025-01-02 00:28:13 +08:00
|
|
|
}
|
|
|
|
|
|
2025-01-04 01:45:24 +08:00
|
|
|
async remove(filePath: string) {
|
|
|
|
|
const access = await this.ctx.accessService.getById<TencentAccess>(this.access.accessId);
|
|
|
|
|
const client = new TencentCosClient({
|
|
|
|
|
access: access,
|
|
|
|
|
logger: this.logger,
|
|
|
|
|
region: this.access.region,
|
|
|
|
|
bucket: this.access.bucket,
|
|
|
|
|
});
|
|
|
|
|
const key = this.rootDir + filePath;
|
|
|
|
|
await client.removeFile(key);
|
|
|
|
|
}
|
2025-01-02 00:28:13 +08:00
|
|
|
}
|