Skip to content

Commit 839123b

Browse files
authored
feat(blob): create delete-folder to delete blob folders (#125)
1 parent 78e316a commit 839123b

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { eventHandler } from 'h3'
2+
import { z } from 'zod'
3+
import { hubBlob } from '../../../utils/blob'
4+
import { requireNuxtHubAuthorization } from '../../../utils/auth'
5+
import { requireNuxtHubFeature } from '../../../utils/features'
6+
7+
export default eventHandler(async (event) => {
8+
await requireNuxtHubAuthorization(event)
9+
requireNuxtHubFeature('blob')
10+
11+
const { prefix } = await readValidatedBody(event, z.object({
12+
prefix: z.string().min(1)
13+
}).parse)
14+
15+
const blob = hubBlob()
16+
17+
let cursor = undefined
18+
const pathnames = []
19+
20+
do {
21+
const blobs = await blob.list({ prefix, limit: 1000, cursor })
22+
pathnames.push(...blobs.blobs.map(blob => blob.pathname))
23+
cursor = blobs.cursor
24+
} while (cursor)
25+
26+
await blob.delete(pathnames)
27+
28+
return sendNoContent(event)
29+
})

0 commit comments

Comments
 (0)