@@ -107,14 +107,14 @@ export function createContentClient(options: ClientOptions): ContentClient {
107
107
return form
108
108
}
109
109
110
- async function buildEntityFormDataForDeploymentV2 (
110
+ async function buildFileUploadRequestsForDeploymentV2 (
111
111
deployData : DeploymentData ,
112
112
options ?: RequestOptions
113
- ) : Promise < Promise < Response > [ ] > {
113
+ ) : Promise < ( ( ) => Promise < Response > ) [ ] > {
114
114
// Check if we are running in node or browser
115
115
const areWeRunningInNode = isNode ( )
116
116
117
- const requests : Promise < Response > [ ] = [ ]
117
+ const requests : ( ( ) => Promise < Response > ) [ ] = [ ]
118
118
const alreadyUploadedHashes = await hashesAlreadyOnServer ( Array . from ( deployData . files . keys ( ) ) , options )
119
119
for ( const [ fileHash , file ] of deployData . files ) {
120
120
if ( ! alreadyUploadedHashes . has ( fileHash ) || fileHash === deployData . entityId ) {
@@ -125,13 +125,14 @@ export function createContentClient(options: ClientOptions): ContentClient {
125
125
: arrayBufferFrom ( file ) // Browser
126
126
127
127
requests . push (
128
- fetcher . fetch ( `${ contentUrl } /v2/entities/${ deployData . entityId } /files/${ fileHash } ` , {
129
- headers : {
130
- 'Content-Type' : 'application/octet-stream'
131
- } ,
132
- method : 'POST' ,
133
- body : content
134
- } )
128
+ ( ) : Promise < Response > =>
129
+ fetcher . fetch ( `${ contentUrl } /v2/entities/${ deployData . entityId } /files/${ fileHash } ` , {
130
+ headers : {
131
+ 'Content-Type' : 'application/octet-stream'
132
+ } ,
133
+ method : 'POST' ,
134
+ body : content
135
+ } )
135
136
)
136
137
}
137
138
}
@@ -165,7 +166,7 @@ export function createContentClient(options: ClientOptions): ContentClient {
165
166
}
166
167
167
168
async function deployV2 ( deployData : DeploymentData , options : RequestOptions = { } ) : Promise < unknown > {
168
- const fileUploadRequests = await buildEntityFormDataForDeploymentV2 ( deployData , options )
169
+ const fileUploadRequests = await buildFileUploadRequestsForDeploymentV2 ( deployData , options )
169
170
170
171
const response = await fetcher . fetch ( `${ contentUrl } /v2/entities/${ deployData . entityId } ` , {
171
172
method : 'POST' ,
@@ -177,13 +178,12 @@ export function createContentClient(options: ClientOptions): ContentClient {
177
178
files : Object . fromEntries ( Array . from ( deployData . files , ( [ key , value ] ) => [ key , value . byteLength ] ) )
178
179
} )
179
180
} )
180
-
181
181
if ( ! response . ok ) {
182
182
throw new Error ( `Failed to deploy entity with id '${ deployData . entityId } '.` )
183
183
}
184
184
console . log ( 'Deployment started successfully! Uploading files...' )
185
185
186
- await Promise . all ( fileUploadRequests )
186
+ await Promise . all ( fileUploadRequests . map ( ( request ) => request ( ) ) )
187
187
console . log ( 'Files uploaded successfully! Finishing deployment...' )
188
188
189
189
const response2 = await fetcher . fetch ( `${ contentUrl } /v2/entities/${ deployData . entityId } ` , {
0 commit comments