Skip to content

Commit 444c382

Browse files
committed
feat: add del as alias of delete for hubBlob()
1 parent b1e0df7 commit 444c382

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

docs/content/docs/2.storage/3.blob.md

+12-2
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ export default eventHandler(async (event) => {
141141

142142
Returns a [`BlobObject`](#blobobject).
143143

144-
### `delete()`
144+
### `del()`
145145

146-
Deletes a blob.
146+
Delete a blob with its pathname.
147147

148148
```ts [server/api/files/[...pathname\\].delete.ts]
149149
export default eventHandler(async (event) => {
@@ -155,6 +155,16 @@ export default eventHandler(async (event) => {
155155
})
156156
```
157157

158+
You can also delete multiple blobs at once by providing an array of pathnames:
159+
160+
```ts
161+
await hubBlob().delete(['images/1.jpg', 'images/2.jpg'])
162+
```
163+
164+
::note
165+
You can also use the `delete()` method as alias of `del()`.
166+
::
167+
158168
#### Params
159169

160170
::field-group

src/server/utils/blob.ts

+13-4
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export function hubBlob() {
5959
}
6060
const bucket = _useBucket()
6161

62-
return {
62+
const blob = {
6363
async list(options: BlobListOptions = { limit: 1000 }) {
6464
const resolvedOptions = defu(options, {
6565
limit: 500,
@@ -126,14 +126,18 @@ export function hubBlob() {
126126

127127
return mapR2ObjectToBlob(object)
128128
},
129-
async delete(pathnames: string | string[]) {
129+
async del(pathnames: string | string[]) {
130130
if (Array.isArray(pathnames)) {
131131
return await bucket.delete(pathnames.map((p) => decodeURI(p)))
132132
} else {
133133
return await bucket.delete(decodeURI(pathnames))
134134
}
135135
}
136136
}
137+
return {
138+
...blob,
139+
delete: blob.del
140+
}
137141
}
138142

139143
export function proxyHubBlob(projectUrl: string, secretKey?: string) {
@@ -144,7 +148,7 @@ export function proxyHubBlob(projectUrl: string, secretKey?: string) {
144148
}
145149
})
146150

147-
return {
151+
const blob = {
148152
async list(options: BlobListOptions = { limit: 1000 }) {
149153
return blobAPI<BlobObject[]>('/', {
150154
method: 'GET',
@@ -174,7 +178,7 @@ export function proxyHubBlob(projectUrl: string, secretKey?: string) {
174178
})
175179
return JSON.parse(headers.get('x-blob') || '{}') as BlobObject
176180
},
177-
async delete(pathnames: string | string[]) {
181+
async del(pathnames: string | string[]) {
178182
if (Array.isArray(pathnames)) {
179183
await blobAPI<void>('/delete', {
180184
method: 'POST',
@@ -190,6 +194,11 @@ export function proxyHubBlob(projectUrl: string, secretKey?: string) {
190194
return
191195
}
192196
}
197+
198+
return {
199+
...blob,
200+
delete: blob.del
201+
}
193202
}
194203

195204
function getContentType(pathOrExtension?: string) {

0 commit comments

Comments
 (0)