import type { DeleteObjectOptions, DeleteObjectResult, PutObjectOptions, PutObjectResult, } from "esdk-obs-nodejs" import ObsClient from "esdk-obs-nodejs" export interface ObsOptions { accessKeyId: string secretAccessKey: string server: string } /** * @see {@link https://www.huaweicloud.com/product/obs.html | 华为云对象存储服务} */ export class Obs { protected obsClient: ObsClient constructor(options: ObsOptions) { this.obsClient = new ObsClient({ access_key_id: options.accessKeyId, secret_access_key: options.secretAccessKey, server: options.server, }) } async putObject(options: PutObjectOptions): Promise { const result = await this.obsClient.putObject(options) if (result.CommonMsg.Status >= 300) { throw new Error(result.CommonMsg.Message) } return result } async deleteObject(options: DeleteObjectOptions): Promise { const result = await this.obsClient.deleteObject(options) if (result.CommonMsg.Status >= 300) { throw new Error(result.CommonMsg.Message) } return result } }