@@ -10,9 +10,9 @@ import { joinURL } from 'ufo'
10
10
11
11
const _r2_buckets : Record < string , R2Bucket > = { }
12
12
13
- function _useBucket ( ) {
13
+ function _useBucket ( ) {
14
14
const name = 'BLOB'
15
- if ( _r2_buckets [ name ] ) {
15
+ if ( _r2_buckets [ name ] && ! process . env . NUXT_HUB_FRESH ) {
16
16
return _r2_buckets [ name ]
17
17
}
18
18
@@ -26,15 +26,15 @@ function _useBucket () {
26
26
return _r2_buckets [ name ]
27
27
}
28
28
29
- export function useBlob ( ) {
29
+ export function useBlob ( ) {
30
30
const proxyURL = import . meta. dev && process . env . NUXT_HUB_URL
31
31
let bucket : R2Bucket
32
32
if ( ! proxyURL ) {
33
33
bucket = _useBucket ( )
34
34
}
35
35
36
36
return {
37
- async list ( options : BlobListOptions = { limit : 1000 } ) {
37
+ async list ( options : BlobListOptions = { limit : 1000 } ) {
38
38
if ( proxyURL ) {
39
39
return ofetch < BlobObject [ ] > ( '/api/_hub/blob' , {
40
40
baseURL : proxyURL ,
@@ -66,7 +66,7 @@ export function useBlob () {
66
66
67
67
return listed . objects . map ( mapR2ObjectToBlob )
68
68
} ,
69
- async serve ( event : H3Event , pathname : string ) {
69
+ async serve ( event : H3Event , pathname : string ) {
70
70
pathname = decodeURI ( pathname )
71
71
if ( proxyURL ) {
72
72
return ofetch < ReadableStreamDefaultReader < any > > ( `/api/_hub/blob/${ pathname } ` , {
@@ -86,7 +86,7 @@ export function useBlob () {
86
86
87
87
return object . body
88
88
} ,
89
- async put ( pathname : string , body : string | ReadableStream < any > | ArrayBuffer | ArrayBufferView | Blob , options : { contentType ?: string , contentLength ?: string , addRandomSuffix ?: boolean , [ key : string ] : any } = { addRandomSuffix : true } ) {
89
+ async put ( pathname : string , body : string | ReadableStream < any > | ArrayBuffer | ArrayBufferView | Blob , options : { contentType ?: string , contentLength ?: string , addRandomSuffix ?: boolean , [ key : string ] : any } = { addRandomSuffix : true } ) {
90
90
pathname = decodeURI ( pathname )
91
91
if ( proxyURL ) {
92
92
const { contentType, contentLength, ...query } = options
@@ -119,7 +119,7 @@ export function useBlob () {
119
119
120
120
return mapR2ObjectToBlob ( object )
121
121
} ,
122
- async head ( pathname : string ) {
122
+ async head ( pathname : string ) {
123
123
pathname = decodeURI ( pathname )
124
124
if ( proxyURL ) {
125
125
const { headers } = await ofetch . raw < void > ( joinURL ( '/api/_hub/blob' , pathname ) , {
@@ -137,7 +137,7 @@ export function useBlob () {
137
137
138
138
return mapR2ObjectToBlob ( object )
139
139
} ,
140
- async delete ( pathname : string ) {
140
+ async delete ( pathname : string ) {
141
141
pathname = decodeURI ( pathname )
142
142
if ( proxyURL ) {
143
143
await ofetch < void > ( `/api/_hub/blob/${ pathname } ` , {
@@ -163,7 +163,7 @@ export function useBlob () {
163
163
// prefix: ''
164
164
// })
165
165
166
- function getContentType ( pathOrExtension ?: string ) {
166
+ function getContentType ( pathOrExtension ?: string ) {
167
167
return ( pathOrExtension && mime . getType ( pathOrExtension ) ) || 'application/octet-stream'
168
168
}
169
169
@@ -195,7 +195,7 @@ function getContentType (pathOrExtension?: string) {
195
195
// return arrayBuffer
196
196
// }
197
197
198
- function mapR2ObjectToBlob ( object : R2Object ) : BlobObject {
198
+ function mapR2ObjectToBlob ( object : R2Object ) : BlobObject {
199
199
return {
200
200
pathname : object . key ,
201
201
contentType : object . httpMetadata ?. contentType ,
0 commit comments