@@ -11,7 +11,7 @@ import { joinURL } from 'ufo'
1111import { streamToArrayBuffer } from '../../../utils/stream'
1212import { requireNuxtHubFeature } from '../../../utils/features'
1313import { getCloudflareAccessHeaders } from '../../../utils/cloudflareAccess'
14- import type { BlobType , FileSizeUnit , BlobUploadedPart , BlobListResult , BlobMultipartUpload , HandleMPUResponse , BlobMultipartOptions , BlobUploadOptions , BlobPutOptions , BlobEnsureOptions , BlobObject , BlobListOptions , BlobCredentialsOptions , BlobCredentials } from '@nuxthub/core'
14+ import type { BlobType , FileSizeUnit , BlobUploadedPart , BlobListResult , BlobMultipartUpload , BlobMultipartOptions , BlobUploadOptions , BlobPutOptions , BlobEnsureOptions , BlobObject , BlobListOptions , BlobCredentialsOptions , BlobCredentials , HubBlob } from '@nuxthub/core'
1515import { useRuntimeConfig } from '#imports'
1616
1717const _r2_buckets : Record < string , R2Bucket > = { }
@@ -33,124 +33,6 @@ function _useBucket(name: string = 'BLOB') {
3333 throw createError ( `Missing Cloudflare ${ name } binding (R2)` )
3434}
3535
36- interface HubBlob {
37- /**
38- * List all the blobs in the bucket (metadata only).
39- *
40- * @param options The list options
41- *
42- * @example ```ts
43- * const { blobs } = await hubBlob().list({ limit: 10 })
44- * ```
45- */
46- list ( options ?: BlobListOptions ) : Promise < BlobListResult >
47- /**
48- * Serve the blob from the bucket.
49- *
50- * @param event The H3 event (needed to set headers for the response)
51- * @param pathname The pathname of the blob
52- *
53- * @example ```ts
54- * export default eventHandler(async (event) => {
55- * return hubBlob().serve(event, '/my-image.jpg')
56- * })
57- * ```
58- */
59- serve ( event : H3Event , pathname : string ) : Promise < ReadableStream < any > >
60- /**
61- * Put a new blob into the bucket.
62- *
63- * @param pathname The pathname of the blob
64- * @param body The blob content
65- * @param options The put options
66- *
67- * @example ```ts
68- * const blob = await hubBlob().put('/my-image.jpg', file)
69- * ```
70- */
71- put ( pathname : string , body : string | ReadableStream < any > | ArrayBuffer | ArrayBufferView | Blob , options ?: BlobPutOptions ) : Promise < BlobObject >
72- /**
73- * Get the blob metadata from the bucket.
74- *
75- * @param pathname The pathname of the blob
76- *
77- * @example ```ts
78- * const blobMetadata = await hubBlob().head('/my-image.jpg')
79- * ```
80- */
81- head ( pathname : string ) : Promise < BlobObject >
82- /**
83- * Get the blob body from the bucket.
84- *
85- * @param pathname The pathname of the blob
86- *
87- * @example ```ts
88- * const blob = await hubBlob().get('/my-image.jpg')
89- * ```
90- */
91- get ( pathname : string ) : Promise < Blob | null >
92- /**
93- * Delete the blob from the bucket.
94- *
95- * @param pathnames The pathname of the blob
96- *
97- * @example ```ts
98- * await hubBlob().del('/my-image.jpg')
99- * ```
100- */
101- del ( pathnames : string | string [ ] ) : Promise < void >
102- /**
103- * Delete the blob from the bucket.
104- *
105- * @param pathnames The pathname of the blob
106- *
107- * @example ```ts
108- * await hubBlob().delete('/my-image.jpg')
109- * ```
110- */
111- delete ( pathnames : string | string [ ] ) : Promise < void >
112- /**
113- * Create a multipart upload.
114- *
115- * @see https://hub.nuxt.com/docs/features/blob#createmultipartupload
116- */
117- createMultipartUpload ( pathname : string , options ?: BlobMultipartOptions ) : Promise < BlobMultipartUpload >
118- /**
119- * Get the specified multipart upload.
120- *
121- * @see https://hub.nuxt.com/docs/features/blob#resumemultipartupload
122- */
123- resumeMultipartUpload ( pathname : string , uploadId : string ) : BlobMultipartUpload
124- /**
125- * Handle the multipart upload request.
126- * Make sure your route includes `[action]` and `[...pathname]` params.
127- *
128- * @see https://hub.nuxt.com/docs/features/blob#handlemultipartupload
129- */
130- handleMultipartUpload ( event : H3Event , options ?: BlobMultipartOptions ) : Promise < HandleMPUResponse >
131- /**
132- * Handle a file upload.
133- *
134- * @param event The H3 event (needed to set headers for the response)
135- * @param options The upload options
136- *
137- * @see https://hub.nuxt.com/docs/features/blob#handleupload
138- */
139- handleUpload ( event : H3Event , options ?: BlobUploadOptions ) : Promise < BlobObject [ ] >
140- /**
141- * Creates temporary access credentials that can be optionally scoped to prefixes or objects.
142- *
143- * Useful to create a signed url to upload directory to R2 from client-side.
144- *
145- * Only available in production or in development with `--remote` flag.
146- *
147- * @example ```ts
148- * const { accountId, bucketName, accessKeyId, secretAccessKey, sessionToken } = await hubBlob().createCredentials()
149- * ```
150- */
151- createCredentials ( options ?: BlobCredentialsOptions ) : Promise < BlobCredentials >
152- }
153-
15436/**
15537 * Access the Blob storage.
15638 *
0 commit comments