node-appwrite 5.0.0 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts CHANGED
@@ -2211,7 +2211,7 @@ declare module "node-appwrite" {
2211
2211
  /**
2212
2212
  * List the currently active function runtimes.
2213
2213
  *
2214
- * Get a list of all runtimes that are currently active in your project.
2214
+ * Get a list of all runtimes that are currently active on your instance.
2215
2215
  *
2216
2216
  * @throws {AppwriteException}
2217
2217
  * @returns {Promise}
package/lib/client.js CHANGED
@@ -10,7 +10,7 @@ class Client {
10
10
  this.endpoint = 'https://HOSTNAME/v1';
11
11
  this.headers = {
12
12
  'content-type': '',
13
- 'x-sdk-version': 'appwrite:nodejs:5.0.0',
13
+ 'x-sdk-version': 'appwrite:nodejs:5.1.0',
14
14
  'X-Appwrite-Response-Format' : '0.13.0',
15
15
  };
16
16
  this.selfSigned = false;
@@ -132,7 +132,7 @@ class Functions extends Service {
132
132
  /**
133
133
  * List the currently active function runtimes.
134
134
  *
135
- * Get a list of all runtimes that are currently active in your project.
135
+ * Get a list of all runtimes that are currently active on your instance.
136
136
  *
137
137
  * @throws {AppwriteException}
138
138
  * @returns {Promise}
@@ -359,53 +359,57 @@ class Functions extends Service {
359
359
  const { size: size } = await promisify(fs.stat)(code);
360
360
 
361
361
  if (size <= client.CHUNK_SIZE) {
362
- payload['code'] = fs.createReadStream(code);
362
+ payload['code'] = fs.createReadStream(code);
363
363
 
364
- return await this.client.call('post', path, {
364
+ return await this.client.call('post', path, {
365
365
  'content-type': 'multipart/form-data',
366
- }, payload);
366
+ }, payload);
367
367
  } else {
368
- let id = undefined;
369
- let response = undefined;
370
-
371
- const totalCounters = Math.ceil(size / client.CHUNK_SIZE);
372
-
373
- for (let counter = 0; counter < totalCounters; counter++) {
374
- const start = (counter * client.CHUNK_SIZE);
375
- const end = Math.min((((counter * client.CHUNK_SIZE) + client.CHUNK_SIZE) - 1), size);
376
- const headers = {
377
- 'content-type': 'multipart/form-data',
378
- 'content-range': 'bytes ' + start + '-' + end + '/' + size
379
- };
380
-
381
- if (id) {
382
- headers['x-appwrite-id'] = id;
383
- }
384
-
385
- const stream = fs.createReadStream(code, {
386
- start,
387
- end
388
- });
389
- payload['code'] = stream;
390
-
391
- response = await this.client.call('post', path, headers, payload);
392
-
393
- if (!id) {
394
- id = response['$id'];
395
- }
396
-
397
- if (onProgress !== null) {
398
- onProgress({
399
- $id: response['$id'],
400
- progress: Math.min((counter+1) * client.CHUNK_SIZE, size) / size * 100,
401
- sizeUploaded: end+1,
402
- chunksTotal: response['chunksTotal'],
403
- chunksUploaded: response['chunksUploaded']
404
- });
405
- }
368
+ let id = undefined;
369
+ let response = undefined;
370
+
371
+ let counter = 0;
372
+ const totalCounters = Math.ceil(size / client.CHUNK_SIZE);
373
+
374
+ const headers = {
375
+ 'content-type': 'multipart/form-data',
376
+ };
377
+
378
+
379
+ for (counter; counter < totalCounters; counter++) {
380
+ const start = (counter * client.CHUNK_SIZE);
381
+ const end = Math.min((((counter * client.CHUNK_SIZE) + client.CHUNK_SIZE) - 1), size);
382
+
383
+ headers['content-range'] = 'bytes ' + start + '-' + end + '/' + size;
384
+
385
+ if (id) {
386
+ headers['x-appwrite-id'] = id;
387
+ }
388
+
389
+ const stream = fs.createReadStream(code, {
390
+ start,
391
+ end
392
+ });
393
+ payload['code'] = stream;
394
+
395
+ response = await this.client.call('post', path, headers, payload);
396
+
397
+ if (!id) {
398
+ id = response['$id'];
399
+ }
400
+
401
+ if (onProgress !== null) {
402
+ onProgress({
403
+ $id: response['$id'],
404
+ progress: Math.min((counter+1) * client.CHUNK_SIZE, size) / size * 100,
405
+ sizeUploaded: end+1,
406
+ chunksTotal: response['chunksTotal'],
407
+ chunksUploaded: response['chunksUploaded']
408
+ });
406
409
  }
410
+ }
407
411
 
408
- return response;
412
+ return response;
409
413
  }
410
414
  }
411
415
 
@@ -372,53 +372,64 @@ class Storage extends Service {
372
372
  const { size: size } = await promisify(fs.stat)(file);
373
373
 
374
374
  if (size <= client.CHUNK_SIZE) {
375
- payload['file'] = fs.createReadStream(file);
375
+ payload['file'] = fs.createReadStream(file);
376
376
 
377
- return await this.client.call('post', path, {
377
+ return await this.client.call('post', path, {
378
378
  'content-type': 'multipart/form-data',
379
- }, payload);
379
+ }, payload);
380
380
  } else {
381
- let id = undefined;
382
- let response = undefined;
383
-
384
- const totalCounters = Math.ceil(size / client.CHUNK_SIZE);
385
-
386
- for (let counter = 0; counter < totalCounters; counter++) {
387
- const start = (counter * client.CHUNK_SIZE);
388
- const end = Math.min((((counter * client.CHUNK_SIZE) + client.CHUNK_SIZE) - 1), size);
389
- const headers = {
390
- 'content-type': 'multipart/form-data',
391
- 'content-range': 'bytes ' + start + '-' + end + '/' + size
392
- };
393
-
394
- if (id) {
395
- headers['x-appwrite-id'] = id;
396
- }
397
-
398
- const stream = fs.createReadStream(file, {
399
- start,
400
- end
401
- });
402
- payload['file'] = stream;
403
-
404
- response = await this.client.call('post', path, headers, payload);
405
-
406
- if (!id) {
407
- id = response['$id'];
408
- }
409
-
410
- if (onProgress !== null) {
411
- onProgress({
412
- $id: response['$id'],
413
- progress: Math.min((counter+1) * client.CHUNK_SIZE, size) / size * 100,
414
- sizeUploaded: end+1,
415
- chunksTotal: response['chunksTotal'],
416
- chunksUploaded: response['chunksUploaded']
417
- });
418
- }
381
+ let id = undefined;
382
+ let response = undefined;
383
+
384
+ let counter = 0;
385
+ const totalCounters = Math.ceil(size / client.CHUNK_SIZE);
386
+
387
+ const headers = {
388
+ 'content-type': 'multipart/form-data',
389
+ };
390
+
391
+ if(fileId != 'unique()') {
392
+ try {
393
+ response = await this.client.call('get', path + '/' + fileId, headers);
394
+ counter = response.chunksUploaded;
395
+ } catch(e) {
396
+ }
397
+ }
398
+
399
+ for (counter; counter < totalCounters; counter++) {
400
+ const start = (counter * client.CHUNK_SIZE);
401
+ const end = Math.min((((counter * client.CHUNK_SIZE) + client.CHUNK_SIZE) - 1), size);
402
+
403
+ headers['content-range'] = 'bytes ' + start + '-' + end + '/' + size;
404
+
405
+ if (id) {
406
+ headers['x-appwrite-id'] = id;
407
+ }
408
+
409
+ const stream = fs.createReadStream(file, {
410
+ start,
411
+ end
412
+ });
413
+ payload['file'] = stream;
414
+
415
+ response = await this.client.call('post', path, headers, payload);
416
+
417
+ if (!id) {
418
+ id = response['$id'];
419
+ }
420
+
421
+ if (onProgress !== null) {
422
+ onProgress({
423
+ $id: response['$id'],
424
+ progress: Math.min((counter+1) * client.CHUNK_SIZE, size) / size * 100,
425
+ sizeUploaded: end+1,
426
+ chunksTotal: response['chunksTotal'],
427
+ chunksUploaded: response['chunksUploaded']
428
+ });
419
429
  }
430
+ }
420
431
 
421
- return response;
432
+ return response;
422
433
  }
423
434
  }
424
435
 
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "node-appwrite",
3
3
  "homepage": "https://appwrite.io/support",
4
4
  "description": "Appwrite is an open-source self-hosted backend server that abstract and simplify complex and repetitive development tasks behind a very simple REST API",
5
- "version": "5.0.0",
5
+ "version": "5.1.0",
6
6
  "license": "BSD-3-Clause",
7
7
  "main": "./index.js",
8
8
  "types": "./index.d.ts",
@@ -12,7 +12,7 @@
12
12
  },
13
13
  "devDependencies": {},
14
14
  "dependencies": {
15
- "axios": "^0.25.0",
15
+ "axios": "^0.26.1",
16
16
  "form-data": "^4.0.0"
17
17
  }
18
18
  }