mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-05-26 10:40:26 +08:00
✨ Feature: support imgur auth upload and delete
This commit is contained in:
@@ -2,14 +2,25 @@ import axios from 'axios'
|
||||
|
||||
export default class ImgurApi {
|
||||
static async delete (configMap: IStringKeyMap): Promise<boolean> {
|
||||
const clientId = configMap.config.clientId
|
||||
const { hash } = configMap
|
||||
const fullUrl = `https://api.imgur.com/3/image/${hash}`
|
||||
const { config = {}, hash = '' } = configMap || {}
|
||||
const { clientId = '', username = '', accessToken = '' } = config
|
||||
const baseUrl = 'https://api.imgur.com/3'
|
||||
let Authorization
|
||||
let apiUrl
|
||||
if (username && accessToken) {
|
||||
Authorization = `Bearer ${accessToken}`
|
||||
apiUrl = `${baseUrl}/account/${username}/image/${hash}`
|
||||
} else if (clientId) {
|
||||
Authorization = `Client-ID ${clientId}`
|
||||
apiUrl = `${baseUrl}/image/${hash}`
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
const headers = {
|
||||
Authorization: `Client-ID ${clientId}`
|
||||
Authorization
|
||||
}
|
||||
try {
|
||||
const res = await axios.delete(fullUrl, {
|
||||
const res = await axios.delete(apiUrl, {
|
||||
headers,
|
||||
timeout: 30000
|
||||
})
|
||||
|
||||
@@ -538,7 +538,7 @@ function handleConfigImport (alias: string) {
|
||||
|
||||
async function getCurrentConfigList () {
|
||||
const configList = await getPicBedsConfig<any>('uploader') ?? {}
|
||||
const pbList = ['aliyun', 'tcyun', 'upyun', 'qiniu', 'smms', 'qiniu', 'github', 'webdavplist', 'aws-s3']
|
||||
const pbList = ['aliyun', 'tcyun', 'upyun', 'qiniu', 'smms', 'qiniu', 'github', 'webdavplist', 'aws-s3', 'imgur']
|
||||
const filteredConfigList = pbList.map((pb) => {
|
||||
const config = configList[pb]
|
||||
if (config && config.configList.length > 0) {
|
||||
@@ -742,6 +742,18 @@ async function transUpToManage (config: IUploaderConfigListItem, picBedName: str
|
||||
)
|
||||
saveConfig(`picBed.${resultMap.alias}`, resultMap)
|
||||
break
|
||||
case 'imgur':
|
||||
alias = `imgur-${config._configName ?? 'Default'}-imp`
|
||||
if (!config.username || !config.accessToken || isImported(alias)) {
|
||||
return
|
||||
}
|
||||
resultMap.alias = alias
|
||||
resultMap.picBedName = 'imgur'
|
||||
resultMap.imgurUserName = config.username
|
||||
resultMap.accessToken = config.accessToken
|
||||
resultMap.proxy = config.proxy || ''
|
||||
saveConfig(`picBed.${resultMap.alias}`, resultMap)
|
||||
break
|
||||
default:
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user