@@ -129,7 +129,7 @@ export class Functions extends Service {
129
129
/**
130
130
* List the currently active function runtimes.
131
131
*
132
- * Get a list of all runtimes that are currently active in your project .
132
+ * Get a list of all runtimes that are currently active on your instance .
133
133
*
134
134
* @throws {AppwriteException }
135
135
* @returns {Promise }
@@ -353,53 +353,57 @@ export class Functions extends Service {
353
353
let id = undefined ;
354
354
let response = undefined ;
355
355
356
+ let counter = 0 ;
356
357
const totalCounters = Math . ceil ( size / Client . CHUNK_SIZE ) ;
357
358
358
- for ( let counter = 0 ; counter < totalCounters ; counter ++ ) {
359
- const start = ( counter * Client . CHUNK_SIZE ) ;
360
- const end = Math . min ( ( ( ( counter * Client . CHUNK_SIZE ) + Client . CHUNK_SIZE ) - 1 ) , size ) ;
361
- const headers : { [ header : string ] : string } = {
362
- 'content-type' : 'multipart/form-data' ,
363
- 'content-range' : 'bytes ' + start + '-' + end + '/' + size
364
- } ;
359
+ const headers : { [ header : string ] : string } = {
360
+ 'content-type' : 'multipart/form-data' ,
361
+ } ;
365
362
366
- if ( id ) {
367
- headers [ 'x-appwrite-id' ] = id ;
368
- }
369
-
370
- const totalBuffer = new Uint8Array ( Client . CHUNK_SIZE ) ;
371
-
372
- for ( let blockIndex = 0 ; blockIndex < Client . CHUNK_SIZE / Client . DENO_READ_CHUNK_SIZE ; blockIndex ++ ) {
373
- const buf = new Uint8Array ( Client . DENO_READ_CHUNK_SIZE ) ;
374
- const cursorPosition = await Deno . seek ( stream . rid , start + ( blockIndex * 16384 ) , Deno . SeekMode . Start ) ;
375
- const numberOfBytesRead = await Deno . read ( stream . rid , buf ) ;
376
363
377
- if ( ! numberOfBytesRead ) {
378
- break ;
379
- }
364
+ for ( counter ; counter < totalCounters ; counter ++ ) {
365
+ const start = ( counter * Client . CHUNK_SIZE ) ;
366
+ const end = Math . min ( ( ( ( counter * Client . CHUNK_SIZE ) + Client . CHUNK_SIZE ) - 1 ) , size ) ;
367
+
368
+ headers [ 'content-range' ] = 'bytes ' + start + '-' + end + '/' + size
380
369
381
- for ( let byteIndex = 0 ; byteIndex < Client . DENO_READ_CHUNK_SIZE ; byteIndex ++ ) {
382
- totalBuffer [ ( blockIndex * Client . DENO_READ_CHUNK_SIZE ) + byteIndex ] = buf [ byteIndex ] ;
383
- }
384
- }
385
-
386
- payload [ 'code' ] = new File ( [ totalBuffer ] , basename ( code ) ) ;
370
+ if ( id ) {
371
+ headers [ 'x-appwrite-id' ] = id ;
372
+ }
373
+
374
+ const totalBuffer = new Uint8Array ( Client . CHUNK_SIZE ) ;
387
375
388
- response = await this . client . call ( 'post' , path , headers , payload ) ;
376
+ for ( let blockIndex = 0 ; blockIndex < Client . CHUNK_SIZE / Client . DENO_READ_CHUNK_SIZE ; blockIndex ++ ) {
377
+ const buf = new Uint8Array ( Client . DENO_READ_CHUNK_SIZE ) ;
378
+ const cursorPosition = await Deno . seek ( stream . rid , start + ( blockIndex * 16384 ) , Deno . SeekMode . Start ) ;
379
+ const numberOfBytesRead = await Deno . read ( stream . rid , buf ) ;
389
380
390
- if ( ! id ) {
391
- id = response [ '$id' ] ;
381
+ if ( ! numberOfBytesRead ) {
382
+ break ;
392
383
}
393
384
394
- if ( onProgress !== null ) {
395
- onProgress ( {
396
- $id : response [ '$id' ] ,
397
- progress : Math . min ( ( counter + 1 ) * Client . CHUNK_SIZE , size ) / size * 100 ,
398
- sizeUploaded : end + 1 ,
399
- chunksTotal : response [ 'chunksTotal' ] ,
400
- chunksUploaded : response [ 'chunksUploaded' ]
401
- } ) ;
385
+ for ( let byteIndex = 0 ; byteIndex < Client . DENO_READ_CHUNK_SIZE ; byteIndex ++ ) {
386
+ totalBuffer [ ( blockIndex * Client . DENO_READ_CHUNK_SIZE ) + byteIndex ] = buf [ byteIndex ] ;
402
387
}
388
+ }
389
+
390
+ payload [ 'code' ] = new File ( [ totalBuffer ] , basename ( code ) ) ;
391
+
392
+ response = await this . client . call ( 'post' , path , headers , payload ) ;
393
+
394
+ if ( ! id ) {
395
+ id = response [ '$id' ] ;
396
+ }
397
+
398
+ if ( onProgress !== null ) {
399
+ onProgress ( {
400
+ $id : response [ '$id' ] ,
401
+ progress : Math . min ( ( counter + 1 ) * Client . CHUNK_SIZE , size ) / size * 100 ,
402
+ sizeUploaded : end + 1 ,
403
+ chunksTotal : response [ 'chunksTotal' ] ,
404
+ chunksUploaded : response [ 'chunksUploaded' ]
405
+ } ) ;
406
+ }
403
407
}
404
408
405
409
return response ;
0 commit comments