mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-07-08 19:12:17 +08:00
🔨 Refactor(custom): refactor private to sharp in es6
This commit is contained in:
@@ -6,17 +6,7 @@ interface IConfigMap {
|
||||
}
|
||||
|
||||
export default class AliyunApi {
|
||||
private static createClient (config: IConfigMap['config']): OSS {
|
||||
const { accessKeyId, accessKeySecret, bucket, area } = config
|
||||
return new OSS({
|
||||
accessKeyId,
|
||||
accessKeySecret,
|
||||
bucket,
|
||||
region: area
|
||||
})
|
||||
}
|
||||
|
||||
private static getKey (fileName: string, path?: string): string {
|
||||
static #getKey (fileName: string, path?: string): string {
|
||||
return path && path !== '/'
|
||||
? `${path.replace(/^\/+|\/+$/, '')}/${fileName}`
|
||||
: fileName
|
||||
@@ -25,8 +15,8 @@ export default class AliyunApi {
|
||||
static async delete (configMap: IConfigMap): Promise<boolean> {
|
||||
const { fileName, config } = configMap
|
||||
try {
|
||||
const client = AliyunApi.createClient(config)
|
||||
const key = AliyunApi.getKey(fileName, config.path)
|
||||
const client = new OSS({ ...config, region: config.area })
|
||||
const key = AliyunApi.#getKey(fileName, config.path)
|
||||
const result = await client.delete(key)
|
||||
return result.res.status === 204
|
||||
} catch (error) {
|
||||
|
||||
@@ -7,13 +7,13 @@ interface IConfigMap {
|
||||
}
|
||||
|
||||
export default class GithubApi {
|
||||
private static createOctokit (token: string) {
|
||||
static #createOctokit (token: string) {
|
||||
return new Octokit({
|
||||
auth: token
|
||||
})
|
||||
}
|
||||
|
||||
private static createKey (path: string | undefined, fileName: string): string {
|
||||
static #createKey (path: string | undefined, fileName: string): string {
|
||||
const formatedFileName = fileName.replace(/%2F/g, '/')
|
||||
return path && path !== '/'
|
||||
? `${path.replace(/^\/+|\/+$/, '')}/${formatedFileName}`
|
||||
@@ -23,8 +23,8 @@ export default class GithubApi {
|
||||
static async delete (configMap: IConfigMap): Promise<boolean> {
|
||||
const { fileName, hash, config: { repo, token, branch, path } } = configMap
|
||||
const [owner, repoName] = repo.split('/')
|
||||
const octokit = GithubApi.createOctokit(token)
|
||||
const key = GithubApi.createKey(path, fileName)
|
||||
const octokit = GithubApi.#createOctokit(token)
|
||||
const key = GithubApi.#createKey(path, fileName)
|
||||
try {
|
||||
const { status } = await octokit.rest.repos.deleteFile({
|
||||
owner,
|
||||
|
||||
@@ -5,28 +5,8 @@ interface IConfigMap {
|
||||
hash?: string
|
||||
}
|
||||
|
||||
interface IConfig {
|
||||
headers: {
|
||||
Authorization: string
|
||||
}
|
||||
timeout: number
|
||||
}
|
||||
|
||||
export default class ImgurApi {
|
||||
static baseUrl = 'https://api.imgur.com/3'
|
||||
private static async makeRequest (
|
||||
method: 'delete',
|
||||
url: string,
|
||||
config: IConfig
|
||||
): Promise<boolean> {
|
||||
try {
|
||||
const response: AxiosResponse = await axios[method](url, config)
|
||||
return response.status === 200
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
return false
|
||||
}
|
||||
}
|
||||
static #baseUrl = 'https://api.imgur.com/3'
|
||||
|
||||
static async delete (configMap: IConfigMap): Promise<boolean> {
|
||||
const {
|
||||
@@ -37,17 +17,22 @@ export default class ImgurApi {
|
||||
|
||||
if (username && accessToken) {
|
||||
Authorization = `Bearer ${accessToken}`
|
||||
apiUrl = `${ImgurApi.baseUrl}/account/${username}/image/${hash}`
|
||||
apiUrl = `${ImgurApi.#baseUrl}/account/${username}/image/${hash}`
|
||||
} else if (clientId) {
|
||||
Authorization = `Client-ID ${clientId}`
|
||||
apiUrl = `${ImgurApi.baseUrl}/image/${hash}`
|
||||
apiUrl = `${ImgurApi.#baseUrl}/image/${hash}`
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
const requestConfig: IConfig = {
|
||||
headers: { Authorization },
|
||||
timeout: 30000
|
||||
try {
|
||||
const response: AxiosResponse = await axios.delete(apiUrl, {
|
||||
headers: { Authorization },
|
||||
timeout: 30000
|
||||
})
|
||||
return response.status === 200
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
return false
|
||||
}
|
||||
return ImgurApi.makeRequest('delete', apiUrl, requestConfig)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ interface IConfigMap {
|
||||
}
|
||||
|
||||
export default class SmmsApi {
|
||||
private static readonly baseUrl = 'https://smms.app/api/v2'
|
||||
static readonly #baseUrl = 'https://smms.app/api/v2'
|
||||
|
||||
static async delete (configMap: IConfigMap): Promise<boolean> {
|
||||
const { hash, config } = configMap
|
||||
@@ -19,7 +19,7 @@ export default class SmmsApi {
|
||||
|
||||
try {
|
||||
const response: AxiosResponse = await axios.get(
|
||||
`${SmmsApi.baseUrl}/delete/${hash}`, {
|
||||
`${SmmsApi.#baseUrl}/delete/${hash}`, {
|
||||
headers: {
|
||||
Authorization: token
|
||||
},
|
||||
|
||||
@@ -6,7 +6,7 @@ interface IConfigMap {
|
||||
}
|
||||
|
||||
export default class TcyunApi {
|
||||
private static createCOS (SecretId: string, SecretKey: string): COS {
|
||||
static #createCOS (SecretId: string, SecretKey: string): COS {
|
||||
return new COS({
|
||||
SecretId,
|
||||
SecretKey
|
||||
@@ -16,7 +16,7 @@ export default class TcyunApi {
|
||||
static async delete (configMap: IConfigMap): Promise<boolean> {
|
||||
const { fileName, config: { secretId, secretKey, bucket, area, path } } = configMap
|
||||
try {
|
||||
const cos = TcyunApi.createCOS(secretId, secretKey)
|
||||
const cos = TcyunApi.#createCOS(secretId, secretKey)
|
||||
let key
|
||||
if (path === '/' || !path) {
|
||||
key = `/${fileName}`
|
||||
|
||||
Reference in New Issue
Block a user