Files
PicList/src/main/apis/delete/smms.ts
2025-07-31 17:37:30 +08:00

46 lines
1.1 KiB
TypeScript

import axios, { AxiosResponse } from 'axios'
import { ISMMSConfig } from '#/types/types'
import { deleteFailedLog, deleteLog } from '~/utils/deleteLog'
interface IConfigMap {
hash?: string
config?: Partial<ISMMSConfig>
}
export default class SmmsApi {
static readonly #baseUrl = 'https://smms.app/api/v2'
static async delete (configMap: IConfigMap): Promise<boolean> {
const { hash, config } = configMap
if (!hash || !config || !config.token) {
deleteLog(hash, 'Smms', false, 'SmmsApi.delete: invalid params')
return false
}
const { token } = config
try {
const response: AxiosResponse = await axios.get(`${SmmsApi.#baseUrl}/delete/${hash}`, {
headers: {
Authorization: token
},
params: {
hash,
format: 'json'
},
timeout: 30000
})
if (response.status === 200) {
deleteLog(hash, 'Smms')
return true
}
deleteLog(hash, 'Smms', false)
return false
} catch (error: any) {
deleteFailedLog(hash, 'Smms', error)
return false
}
}
}