-
Notifications
You must be signed in to change notification settings - Fork 393
/
Copy pathblobs-delete.ts
31 lines (25 loc) · 952 Bytes
/
blobs-delete.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
import { getStore } from '@netlify/blobs'
import { chalk, logAndThrowError, log } from '../../utils/command-helpers.js'
import { promptBlobDelete } from '../../utils/prompts/blob-delete-prompts.js'
/**
* The blobs:delete command
*/
export const blobsDelete = async (storeName: string, key: string, _options: Record<string, unknown>, command: any) => {
const { api, siteInfo } = command.netlify
const { force } = _options
const store = getStore({
apiURL: `${api.scheme}://${api.host}`,
name: storeName,
siteID: siteInfo.id ?? '',
token: api.accessToken ?? '',
})
if (force === undefined) {
await promptBlobDelete(key, storeName)
}
try {
await store.delete(key)
log(`${chalk.greenBright('Success')}: Blob ${chalk.yellow(key)} deleted from store ${chalk.yellow(storeName)}`)
} catch {
return logAndThrowError(`Could not delete blob ${chalk.yellow(key)} from store ${chalk.yellow(storeName)}`)
}
}