diff --git a/src/renderer/apis/allApi.ts b/src/renderer/apis/allApi.ts index 743f6bd..d5cbde9 100644 --- a/src/renderer/apis/allApi.ts +++ b/src/renderer/apis/allApi.ts @@ -13,6 +13,7 @@ import DogeCloudApi from './dogecloud' import HuaweicloudApi from './huaweiyun' import AlistApi from './alist' import PiclistApi from './piclist' +import LskyplistApi from './lskyplist' const apiMap: IStringKeyMap = { aliyun: AliyunApi, @@ -29,7 +30,8 @@ const apiMap: IStringKeyMap = { dogecloud: DogeCloudApi, 'huaweicloud-uploader': HuaweicloudApi, alist: AlistApi, - piclist: PiclistApi + piclist: PiclistApi, + lskyplist: LskyplistApi } export default class ALLApi { diff --git a/src/renderer/apis/lskyplist.ts b/src/renderer/apis/lskyplist.ts new file mode 100644 index 0000000..2db3842 --- /dev/null +++ b/src/renderer/apis/lskyplist.ts @@ -0,0 +1,39 @@ +import axios, { AxiosResponse } from 'axios' +import https from 'https' + +export default class LskyplistApi { + static async delete (configMap: IStringKeyMap): Promise { + const { hash, config } = configMap + if (!hash || !config || !config.token) { + console.error('LskyplistApi.delete: invalid params') + return false + } + + const { host, token, version } = config + if (version !== 'V2') { + console.error('LskyplistApi.delete: invalid version') + return false + } + + const v2Headers = { + Accept: 'application/json', + Authorization: token || undefined + } + + const requestAgent = new https.Agent({ + rejectUnauthorized: false + }) + try { + const response: AxiosResponse = await axios.delete( + `${host}/api/v1/images/${hash}`, { + headers: v2Headers, + timeout: 30000, + httpsAgent: requestAgent + }) + return response.status === 200 && response.data.status === true + } catch (error) { + console.error(error) + return false + } + } +} diff --git a/src/universal/utils/static.ts b/src/universal/utils/static.ts index 8d3ad84..c7965c2 100644 --- a/src/universal/utils/static.ts +++ b/src/universal/utils/static.ts @@ -21,5 +21,6 @@ export const picBedsCanbeDeleted = [ 'dogecloud', 'huaweicloud-uploader', 'alist', - 'piclist' + 'piclist', + 'lskyplist' ]