@@ -73,6 +73,7 @@ import {
7373 SetMetadataOptions ,
7474} from './nodejs-common/service-object.js' ;
7575import {
76+ Gaxios ,
7677 GaxiosError ,
7778 GaxiosInterceptor ,
7879 GaxiosOptionsPrepared ,
@@ -82,7 +83,6 @@ import {
8283 StorageQueryParameters ,
8384 StorageRequestOptions ,
8485} from './storage-transport.js' ;
85- import * as gaxios from 'gaxios' ;
8686import mime from 'mime' ;
8787
8888export type GetExpirationDateResponse = [ Date ] ;
@@ -1412,6 +1412,7 @@ class File extends ServiceObject<File, FileMetadata> {
14121412 } else if ( newFile . kmsKeyName !== undefined ) {
14131413 query . destinationKmsKeyName = newFile . kmsKeyName ;
14141414 }
1415+ headers . set ( 'Content-Type' , 'application/json' ) ;
14151416
14161417 if ( query . destinationKmsKeyName ) {
14171418 this . kmsKeyName = query . destinationKmsKeyName ;
@@ -1441,7 +1442,7 @@ class File extends ServiceObject<File, FileMetadata> {
14411442 . makeRequest < RewriteResponse > (
14421443 {
14431444 method : 'POST' ,
1444- url : `/b/${ this . bucket . name } /o/${ encodeURIComponent ( this . name ) } /rewriteTo/b/${
1445+ url : `/storage/v1/ b/${ this . bucket . name } /o/${ encodeURIComponent ( this . name ) } /rewriteTo/b/${
14451446 destBucket . name
14461447 } /o/${ encodeURIComponent ( newFile . name ) } `,
14471448 queryParameters : query as unknown as StorageQueryParameters ,
@@ -1730,7 +1731,7 @@ class File extends ServiceObject<File, FileMetadata> {
17301731 }
17311732
17321733 const reqOpts : StorageRequestOptions = {
1733- url : `${ this . bucket . baseUrl } / ${ this . bucket . name } ${ this . baseUrl } / ${ this . name } ` ,
1734+ url : `/storage/v1/b/ ${ this . bucket . name } /o/ ${ encodeURIComponent ( this . name ) } ` ,
17341735 headers,
17351736 queryParameters : query as unknown as StorageQueryParameters ,
17361737 responseType : 'stream' ,
@@ -3309,22 +3310,18 @@ class File extends ServiceObject<File, FileMetadata> {
33093310 */
33103311
33113312 isPublic ( callback ?: IsPublicCallback ) : Promise < IsPublicResponse > | void {
3312- // Build any custom headers based on the defined interceptors on the parent
3313- // storage object and this object
3314- const storageInterceptors = this . storage ?. interceptors || [ ] ;
3315- const fileInterceptors = this . interceptors || [ ] ;
3316- const allInterceptors = storageInterceptors . concat ( fileInterceptors ) ;
3317-
3318- for ( const curInter of allInterceptors ) {
3319- gaxios . instance . interceptors . request . add ( curInter ) ;
3320- }
3313+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3314+ const { callback : cb } = normalize < any , IsPublicCallback > (
3315+ undefined ,
3316+ callback ,
3317+ ) ;
3318+ const url = `${ this . storage . apiEndpoint } /${ this . bucket . name } /${ encodeURIComponent ( this . name ) } ` ;
33213319
3320+ const gaxios = new Gaxios ( ) ;
33223321 gaxios
33233322 . request ( {
33243323 method : 'GET' ,
3325- url : `${ this . storage . apiEndpoint } /${
3326- this . bucket . name
3327- } /${ encodeURIComponent ( this . name ) } `,
3324+ url,
33283325 retryConfig : {
33293326 retry : this . storage . retryOptions . maxRetries ,
33303327 noResponseRetries : this . storage . retryOptions . maxRetries ,
@@ -3334,12 +3331,17 @@ class File extends ServiceObject<File, FileMetadata> {
33343331 totalTimeout : this . storage . retryOptions . totalTimeout ,
33353332 } ,
33363333 } )
3337- . then ( ( ) => callback ! ( null , true ) )
3334+ . then ( ( ) => {
3335+ cb ( null , true ) ;
3336+ } )
33383337 . catch ( err => {
3339- if ( err . status === 403 ) {
3340- callback ! ( null , false ) ;
3338+ const status = err . response ?. status ;
3339+ // 401 Unauthorized or 403 Forbidden means the object is NOT public.
3340+ if ( status === 401 || status === 403 ) {
3341+ cb ( null , false ) ;
33413342 } else {
3342- callback ! ( err ) ;
3343+ // Any other error (like 404) is a real error.
3344+ cb ( err ) ;
33433345 }
33443346 } ) ;
33453347 }
@@ -3687,7 +3689,7 @@ class File extends ServiceObject<File, FileMetadata> {
36873689 . makeRequest (
36883690 {
36893691 method : 'POST' ,
3690- url : `/b/${ this . bucket . name } /o/${ encodeURIComponent ( this . name ) } /moveTo/o/${ encodeURIComponent ( newFile . name ) } ` ,
3692+ url : `/storage/v1/ b/${ this . bucket . name } /o/${ encodeURIComponent ( this . name ) } /moveTo/o/${ encodeURIComponent ( newFile . name ) } ` ,
36913693 queryParameters : query as StorageQueryParameters ,
36923694 body : JSON . stringify ( options ) ,
36933695 } ,
@@ -4018,7 +4020,7 @@ class File extends ServiceObject<File, FileMetadata> {
40184020 async restore ( options : RestoreOptions ) : Promise < File > {
40194021 const file = await this . storageTransport . makeRequest < File > ( {
40204022 method : 'POST' ,
4021- url : `/b/${ this . bucket . name } /o/${ encodeURIComponent ( this . name ) } /restore` ,
4023+ url : `/storage/v1/ b/${ this . bucket . name } /o/${ encodeURIComponent ( this . name ) } /restore` ,
40224024 queryParameters : options as unknown as StorageQueryParameters ,
40234025 } ) ;
40244026 return file as File ;
0 commit comments