-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhandleDelete.ts
42 lines (36 loc) · 921 Bytes
/
handleDelete.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import type { HandleDelete } from '@payloadcms/plugin-cloud-storage/types'
import type { Octokit } from 'octokit'
import path from 'node:path'
import type { GithubAuthor } from './types'
import { getFileSHA } from './utilities'
interface Args {
author?: GithubAuthor
branch: string
committer?: GithubAuthor
getStorageClient: () => Octokit
owner: string
repo: string
}
export const getHandleDelete = ({
author,
branch,
committer,
getStorageClient,
owner,
repo,
}: Args): HandleDelete => {
return async ({ doc, filename }) => {
const prefix = doc.prefix || ''
const sha = await getFileSHA(getStorageClient, owner, repo, branch, prefix, filename)
await getStorageClient().rest.repos.deleteFile({
author,
branch,
committer,
message: `:x: Delete "${filename}"`,
owner,
path: path.posix.join(prefix, filename),
repo,
sha,
})
}
}