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 +1 -1
- package/lib/client.js +1 -1
- package/lib/services/functions.js +47 -43
- package/lib/services/storage.js +53 -42
- package/package.json +2 -2
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
|
|
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.
|
|
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
|
|
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
|
-
|
|
362
|
+
payload['code'] = fs.createReadStream(code);
|
|
363
363
|
|
|
364
|
-
|
|
364
|
+
return await this.client.call('post', path, {
|
|
365
365
|
'content-type': 'multipart/form-data',
|
|
366
|
-
|
|
366
|
+
}, payload);
|
|
367
367
|
} else {
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
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
|
-
|
|
412
|
+
return response;
|
|
409
413
|
}
|
|
410
414
|
}
|
|
411
415
|
|
package/lib/services/storage.js
CHANGED
|
@@ -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
|
-
|
|
375
|
+
payload['file'] = fs.createReadStream(file);
|
|
376
376
|
|
|
377
|
-
|
|
377
|
+
return await this.client.call('post', path, {
|
|
378
378
|
'content-type': 'multipart/form-data',
|
|
379
|
-
|
|
379
|
+
}, payload);
|
|
380
380
|
} else {
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
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
|
-
|
|
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.
|
|
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.
|
|
15
|
+
"axios": "^0.26.1",
|
|
16
16
|
"form-data": "^4.0.0"
|
|
17
17
|
}
|
|
18
18
|
}
|