mirror of
https://github.com/Kuingsmile/PicList.git
synced 2025-02-11 06:38:13 -05:00
32 lines
824 B
TypeScript
32 lines
824 B
TypeScript
![]() |
import { Octokit } from '@octokit/rest'
|
||
|
|
||
|
export default class GithubApi {
|
||
|
static async delete (configMap: IStringKeyMap): Promise<boolean> {
|
||
|
const { fileName, hash, config: { repo, token, branch, path } } = configMap
|
||
|
const owner = repo.split('/')[0]
|
||
|
const repoName = repo.split('/')[1]
|
||
|
const octokit = new Octokit({
|
||
|
auth: token
|
||
|
})
|
||
|
let key
|
||
|
if (path === '/' || !path) {
|
||
|
key = fileName
|
||
|
} else {
|
||
|
key = `${path.replace(/^\//, '').replace(/\/$/, '')}/${fileName}`
|
||
|
}
|
||
|
try {
|
||
|
const result = await octokit.rest.repos.deleteFile({
|
||
|
owner,
|
||
|
repo: repoName,
|
||
|
path: key,
|
||
|
message: `delete ${fileName} by PicList`,
|
||
|
sha: hash,
|
||
|
branch
|
||
|
})
|
||
|
return result.status === 200
|
||
|
} catch (error) {
|
||
|
return false
|
||
|
}
|
||
|
}
|
||
|
}
|