@@ -33,11 +33,16 @@ import {
33
33
unknown
34
34
} from './error' ;
35
35
import { Location } from './location' ;
36
- import * as MetadataUtils from './metadata' ;
37
- import * as ListResultUtils from './list' ;
36
+ import {
37
+ Mappings ,
38
+ fromResourceString ,
39
+ downloadUrlFromResourceString ,
40
+ toResourceString
41
+ } from './metadata' ;
42
+ import { fromResponseString } from './list' ;
38
43
import { RequestInfo , UrlParams } from './requestinfo' ;
39
- import * as type from './type' ;
40
- import * as UrlUtils from './url' ;
44
+ import { isString } from './type' ;
45
+ import { makeUrl } from './url' ;
41
46
import { XhrIo } from './xhrio' ;
42
47
import { StorageService } from '../service' ;
43
48
@@ -52,10 +57,10 @@ export function handlerCheck(cndn: boolean): void {
52
57
53
58
export function metadataHandler (
54
59
service : StorageService ,
55
- mappings : MetadataUtils . Mappings
60
+ mappings : Mappings
56
61
) : ( p1 : XhrIo , p2 : string ) => Metadata {
57
62
function handler ( xhr : XhrIo , text : string ) : Metadata {
58
- const metadata = MetadataUtils . fromResourceString ( service , text , mappings ) ;
63
+ const metadata = fromResourceString ( service , text , mappings ) ;
59
64
handlerCheck ( metadata !== null ) ;
60
65
return metadata as Metadata ;
61
66
}
@@ -67,11 +72,7 @@ export function listHandler(
67
72
bucket : string
68
73
) : ( p1 : XhrIo , p2 : string ) => ListResult {
69
74
function handler ( xhr : XhrIo , text : string ) : ListResult {
70
- const listResult = ListResultUtils . fromResponseString (
71
- service ,
72
- bucket ,
73
- text
74
- ) ;
75
+ const listResult = fromResponseString ( service , bucket , text ) ;
75
76
handlerCheck ( listResult !== null ) ;
76
77
return listResult as ListResult ;
77
78
}
@@ -80,15 +81,12 @@ export function listHandler(
80
81
81
82
export function downloadUrlHandler (
82
83
service : StorageService ,
83
- mappings : MetadataUtils . Mappings
84
+ mappings : Mappings
84
85
) : ( p1 : XhrIo , p2 : string ) => string | null {
85
86
function handler ( xhr : XhrIo , text : string ) : string | null {
86
- const metadata = MetadataUtils . fromResourceString ( service , text , mappings ) ;
87
+ const metadata = fromResourceString ( service , text , mappings ) ;
87
88
handlerCheck ( metadata !== null ) ;
88
- return MetadataUtils . downloadUrlFromResourceString (
89
- metadata as Metadata ,
90
- text
91
- ) ;
89
+ return downloadUrlFromResourceString ( metadata as Metadata , text ) ;
92
90
}
93
91
return handler ;
94
92
}
@@ -142,10 +140,10 @@ export function objectErrorHandler(
142
140
export function getMetadata (
143
141
service : StorageService ,
144
142
location : Location ,
145
- mappings : MetadataUtils . Mappings
143
+ mappings : Mappings
146
144
) : RequestInfo < Metadata > {
147
145
const urlPart = location . fullServerUrl ( ) ;
148
- const url = UrlUtils . makeUrl ( urlPart ) ;
146
+ const url = makeUrl ( urlPart ) ;
149
147
const method = 'GET' ;
150
148
const timeout = service . maxOperationRetryTime ;
151
149
const requestInfo = new RequestInfo (
@@ -181,7 +179,7 @@ export function list(
181
179
urlParams [ 'maxResults' ] = maxResults ;
182
180
}
183
181
const urlPart = location . bucketOnlyServerUrl ( ) ;
184
- const url = UrlUtils . makeUrl ( urlPart ) ;
182
+ const url = makeUrl ( urlPart ) ;
185
183
const method = 'GET' ;
186
184
const timeout = service . maxOperationRetryTime ;
187
185
const requestInfo = new RequestInfo (
@@ -198,10 +196,10 @@ export function list(
198
196
export function getDownloadUrl (
199
197
service : StorageService ,
200
198
location : Location ,
201
- mappings : MetadataUtils . Mappings
199
+ mappings : Mappings
202
200
) : RequestInfo < string | null > {
203
201
const urlPart = location . fullServerUrl ( ) ;
204
- const url = UrlUtils . makeUrl ( urlPart ) ;
202
+ const url = makeUrl ( urlPart ) ;
205
203
const method = 'GET' ;
206
204
const timeout = service . maxOperationRetryTime ;
207
205
const requestInfo = new RequestInfo (
@@ -217,13 +215,13 @@ export function getDownloadUrl(
217
215
export function updateMetadata (
218
216
service : StorageService ,
219
217
location : Location ,
220
- metadata : { [ key : string ] : unknown } ,
221
- mappings : MetadataUtils . Mappings
218
+ metadata : Record < string , unknown > ,
219
+ mappings : Mappings
222
220
) : RequestInfo < Metadata > {
223
221
const urlPart = location . fullServerUrl ( ) ;
224
- const url = UrlUtils . makeUrl ( urlPart ) ;
222
+ const url = makeUrl ( urlPart ) ;
225
223
const method = 'PATCH' ;
226
- const body = MetadataUtils . toResourceString ( metadata , mappings ) ;
224
+ const body = toResourceString ( metadata , mappings ) ;
227
225
const headers = { 'Content-Type' : 'application/json; charset=utf-8' } ;
228
226
const timeout = service . maxOperationRetryTime ;
229
227
const requestInfo = new RequestInfo (
@@ -243,7 +241,7 @@ export function deleteObject(
243
241
location : Location
244
242
) : RequestInfo < void > {
245
243
const urlPart = location . fullServerUrl ( ) ;
246
- const url = UrlUtils . makeUrl ( urlPart ) ;
244
+ const url = makeUrl ( urlPart ) ;
247
245
const method = 'DELETE' ;
248
246
const timeout = service . maxOperationRetryTime ;
249
247
@@ -285,18 +283,19 @@ export function metadataForUpload_(
285
283
export function simpleUpload (
286
284
service : StorageService ,
287
285
location : Location ,
288
- mappings : MetadataUtils . Mappings ,
286
+ mappings : Mappings ,
289
287
blob : FbsBlob ,
290
288
metadata ?: Metadata | null
291
289
) : RequestInfo < Metadata > {
292
290
const urlPart = location . bucketOnlyServerUrl ( ) ;
293
- const headers : { [ prop : string ] : string } = {
294
- 'Content-Type' : 'application/octet-stream'
295
- } ;
296
291
297
292
const metadata_ = metadataForUpload_ ( location , blob , metadata ) ;
293
+ const headers : { [ prop : string ] : string } = {
294
+ // metadataForUpload_ always populates the contentType field.
295
+ 'Content-Type' : metadata_ [ 'contentType' ] !
296
+ } ;
298
297
const urlParams : UrlParams = { name : metadata_ [ 'fullPath' ] ! } ;
299
- const url = UrlUtils . makeUrl ( urlPart ) ;
298
+ const url = makeUrl ( urlPart ) ;
300
299
const method = 'POST' ;
301
300
const timeout = service . maxUploadRetryTime ;
302
301
const requestInfo = new RequestInfo (
@@ -317,7 +316,7 @@ export function simpleUpload(
317
316
export function multipartUpload (
318
317
service : StorageService ,
319
318
location : Location ,
320
- mappings : MetadataUtils . Mappings ,
319
+ mappings : Mappings ,
321
320
blob : FbsBlob ,
322
321
metadata ?: Metadata | null
323
322
) : RequestInfo < Metadata > {
@@ -336,7 +335,7 @@ export function multipartUpload(
336
335
const boundary = genBoundary ( ) ;
337
336
headers [ 'Content-Type' ] = 'multipart/related; boundary=' + boundary ;
338
337
const metadata_ = metadataForUpload_ ( location , blob , metadata ) ;
339
- const metadataString = MetadataUtils . toResourceString ( metadata_ , mappings ) ;
338
+ const metadataString = toResourceString ( metadata_ , mappings ) ;
340
339
const preBlobPart =
341
340
'--' +
342
341
boundary +
@@ -355,7 +354,7 @@ export function multipartUpload(
355
354
throw cannotSliceBlob ( ) ;
356
355
}
357
356
const urlParams : UrlParams = { name : metadata_ [ 'fullPath' ] ! } ;
358
- const url = UrlUtils . makeUrl ( urlPart ) ;
357
+ const url = makeUrl ( urlPart ) ;
359
358
const method = 'POST' ;
360
359
const timeout = service . maxUploadRetryTime ;
361
360
const requestInfo = new RequestInfo (
@@ -408,14 +407,14 @@ export function checkResumeHeader_(xhr: XhrIo, allowed?: string[]): string {
408
407
export function createResumableUpload (
409
408
service : StorageService ,
410
409
location : Location ,
411
- mappings : MetadataUtils . Mappings ,
410
+ mappings : Mappings ,
412
411
blob : FbsBlob ,
413
412
metadata ?: Metadata | null
414
413
) : RequestInfo < string > {
415
414
const urlPart = location . bucketOnlyServerUrl ( ) ;
416
415
const metadataForUpload = metadataForUpload_ ( location , blob , metadata ) ;
417
416
const urlParams : UrlParams = { name : metadataForUpload [ 'fullPath' ] ! } ;
418
- const url = UrlUtils . makeUrl ( urlPart ) ;
417
+ const url = makeUrl ( urlPart ) ;
419
418
const method = 'POST' ;
420
419
const headers = {
421
420
'X-Goog-Upload-Protocol' : 'resumable' ,
@@ -424,7 +423,7 @@ export function createResumableUpload(
424
423
'X-Goog-Upload-Header-Content-Type' : metadataForUpload [ 'contentType' ] ! ,
425
424
'Content-Type' : 'application/json; charset=utf-8'
426
425
} ;
427
- const body = MetadataUtils . toResourceString ( metadataForUpload , mappings ) ;
426
+ const body = toResourceString ( metadataForUpload , mappings ) ;
428
427
const timeout = service . maxUploadRetryTime ;
429
428
430
429
function handler ( xhr : XhrIo ) : string {
@@ -435,7 +434,7 @@ export function createResumableUpload(
435
434
} catch ( e ) {
436
435
handlerCheck ( false ) ;
437
436
}
438
- handlerCheck ( type . isString ( url ) ) ;
437
+ handlerCheck ( isString ( url ) ) ;
439
438
return url as string ;
440
439
}
441
440
const requestInfo = new RequestInfo ( url , method , handler , timeout ) ;
@@ -504,7 +503,7 @@ export function continueResumableUpload(
504
503
url : string ,
505
504
blob : FbsBlob ,
506
505
chunkSize : number ,
507
- mappings : MetadataUtils . Mappings ,
506
+ mappings : Mappings ,
508
507
status ?: ResumableUploadStatus | null ,
509
508
progressCallback ?: ( ( p1 : number , p2 : number ) => void ) | null
510
509
) : RequestInfo < ResumableUploadStatus > {
0 commit comments