@@ -191,7 +191,8 @@ export function hubBlob(): HubBlob {
191
191
}
192
192
} ,
193
193
async serve ( event : H3Event , pathname : string ) {
194
- const object = await bucket . get ( decodeURI ( pathname ) )
194
+ pathname = decodeURIComponent ( pathname )
195
+ const object = await bucket . get ( pathname )
195
196
196
197
if ( ! object ) {
197
198
throw createError ( { message : 'File not found' , statusCode : 404 } )
@@ -204,7 +205,7 @@ export function hubBlob(): HubBlob {
204
205
return object . body
205
206
} ,
206
207
async get ( pathname : string ) : Promise < Blob | null > {
207
- const object = await bucket . get ( decodeURI ( pathname ) )
208
+ const object = await bucket . get ( decodeURIComponent ( pathname ) )
208
209
209
210
if ( ! object ) {
210
211
return null
@@ -213,7 +214,7 @@ export function hubBlob(): HubBlob {
213
214
return object . blob ( ) as Promise < Blob >
214
215
} ,
215
216
async put ( pathname : string , body : string | ReadableStream < any > | ArrayBuffer | ArrayBufferView | Blob , options : BlobPutOptions = { } ) {
216
- pathname = decodeURI ( pathname )
217
+ pathname = decodeURIComponent ( pathname )
217
218
const { contentType : optionsContentType , contentLength, addRandomSuffix, prefix, customMetadata } = options
218
219
const contentType = optionsContentType || ( body as Blob ) . type || getContentType ( pathname )
219
220
@@ -238,7 +239,7 @@ export function hubBlob(): HubBlob {
238
239
return mapR2ObjectToBlob ( object )
239
240
} ,
240
241
async head ( pathname : string ) {
241
- const object = await bucket . head ( decodeURI ( pathname ) )
242
+ const object = await bucket . head ( decodeURIComponent ( pathname ) )
242
243
243
244
if ( ! object ) {
244
245
throw createError ( { message : 'Blob not found' , statusCode : 404 } )
@@ -248,13 +249,13 @@ export function hubBlob(): HubBlob {
248
249
} ,
249
250
async del ( pathnames : string | string [ ] ) {
250
251
if ( Array . isArray ( pathnames ) ) {
251
- return await bucket . delete ( pathnames . map ( p => decodeURI ( p ) ) )
252
+ return await bucket . delete ( pathnames . map ( p => decodeURIComponent ( p ) ) )
252
253
} else {
253
- return await bucket . delete ( decodeURI ( pathnames ) )
254
+ return await bucket . delete ( decodeURIComponent ( pathnames ) )
254
255
}
255
256
} ,
256
257
async createMultipartUpload ( pathname : string , options : BlobMultipartOptions = { } ) : Promise < BlobMultipartUpload > {
257
- pathname = decodeURI ( pathname )
258
+ pathname = decodeURIComponent ( pathname )
258
259
const { contentType : optionsContentType , contentLength, addRandomSuffix, prefix, customMetadata } = options
259
260
const contentType = optionsContentType || getContentType ( pathname )
260
261
@@ -278,7 +279,7 @@ export function hubBlob(): HubBlob {
278
279
return mapR2MpuToBlobMpu ( mpu )
279
280
} ,
280
281
resumeMultipartUpload ( pathname : string , uploadId : string ) {
281
- const mpu = bucket . resumeMultipartUpload ( pathname , uploadId )
282
+ const mpu = bucket . resumeMultipartUpload ( decodeURIComponent ( pathname ) , uploadId )
282
283
283
284
return mapR2MpuToBlobMpu ( mpu )
284
285
} ,
@@ -375,7 +376,7 @@ export function proxyHubBlob(projectUrl: string, secretKey?: string): HubBlob {
375
376
} )
376
377
} ,
377
378
async serve ( _event : H3Event , pathname : string ) {
378
- return blobAPI < ReadableStream < any > > ( decodeURI ( pathname ) , {
379
+ return blobAPI < ReadableStream < any > > ( encodeURIComponent ( pathname ) , {
379
380
method : 'GET'
380
381
} )
381
382
} ,
@@ -391,20 +392,20 @@ export function proxyHubBlob(projectUrl: string, secretKey?: string): HubBlob {
391
392
if ( body instanceof Uint8Array ) {
392
393
body = new Blob ( [ body ] )
393
394
}
394
- return await blobAPI < BlobObject > ( decodeURI ( pathname ) , {
395
+ return await blobAPI < BlobObject > ( encodeURIComponent ( pathname ) , {
395
396
method : 'PUT' ,
396
397
headers,
397
398
body,
398
399
query
399
400
} )
400
401
} ,
401
402
async head ( pathname : string ) : Promise < BlobObject > {
402
- return await blobAPI ( `/head/${ decodeURI ( pathname ) } ` , {
403
+ return await blobAPI ( `/head/${ encodeURIComponent ( pathname ) } ` , {
403
404
method : 'GET'
404
405
} )
405
406
} ,
406
407
async get ( pathname : string ) : Promise < Blob > {
407
- return await blobAPI ( `/${ decodeURI ( pathname ) } ` , {
408
+ return await blobAPI ( `/${ encodeURIComponent ( pathname ) } ` , {
408
409
method : 'GET' ,
409
410
responseType : 'blob'
410
411
} )
@@ -414,18 +415,18 @@ export function proxyHubBlob(projectUrl: string, secretKey?: string): HubBlob {
414
415
await blobAPI ( '/delete' , {
415
416
method : 'POST' ,
416
417
body : {
417
- pathnames : pathnames . map ( p => decodeURI ( p ) )
418
+ pathnames : pathnames . map ( p => encodeURIComponent ( p ) )
418
419
}
419
420
} )
420
421
} else {
421
- await blobAPI ( decodeURI ( pathnames ) , {
422
+ await blobAPI ( encodeURIComponent ( pathnames ) , {
422
423
method : 'DELETE'
423
424
} )
424
425
}
425
426
return
426
427
} ,
427
428
async createMultipartUpload ( pathname : string , options : BlobMultipartOptions = { } ) {
428
- return await blobAPI < BlobMultipartUpload > ( `/multipart/create/${ decodeURI ( pathname ) } ` , {
429
+ return await blobAPI < BlobMultipartUpload > ( `/multipart/create/${ encodeURIComponent ( pathname ) } ` , {
429
430
method : 'POST' ,
430
431
query : options
431
432
} )
@@ -435,7 +436,7 @@ export function proxyHubBlob(projectUrl: string, secretKey?: string): HubBlob {
435
436
pathname,
436
437
uploadId,
437
438
async uploadPart ( partNumber : number , body : string | ReadableStream < any > | ArrayBuffer | ArrayBufferView | Blob ) : Promise < BlobUploadedPart > {
438
- return await blobAPI < BlobUploadedPart > ( `/multipart/upload/${ decodeURI ( pathname ) } ` , {
439
+ return await blobAPI < BlobUploadedPart > ( `/multipart/upload/${ encodeURIComponent ( pathname ) } ` , {
439
440
method : 'PUT' ,
440
441
query : {
441
442
uploadId,
@@ -445,15 +446,15 @@ export function proxyHubBlob(projectUrl: string, secretKey?: string): HubBlob {
445
446
} )
446
447
} ,
447
448
async abort ( ) : Promise < void > {
448
- await blobAPI ( `/multipart/abort/${ decodeURI ( pathname ) } ` , {
449
+ await blobAPI ( `/multipart/abort/${ encodeURIComponent ( pathname ) } ` , {
449
450
method : 'DELETE' ,
450
451
query : {
451
452
uploadId
452
453
}
453
454
} )
454
455
} ,
455
456
async complete ( parts : BlobUploadedPart [ ] ) : Promise < BlobObject > {
456
- return await blobAPI < BlobObject > ( `/multipart/complete/${ decodeURI ( pathname ) } ` , {
457
+ return await blobAPI < BlobObject > ( `/multipart/complete/${ encodeURIComponent ( pathname ) } ` , {
457
458
method : 'POST' ,
458
459
query : {
459
460
uploadId
0 commit comments