node-appwrite 6.0.0 → 7.0.2
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/README.md +2 -2
- package/docs/examples/account/create-phone-verification.md +20 -0
- package/docs/examples/account/create-recovery.md +3 -3
- package/docs/examples/account/create-verification.md +3 -3
- package/docs/examples/account/delete-session.md +3 -3
- package/docs/examples/account/delete-sessions.md +3 -3
- package/docs/examples/account/get-logs.md +3 -3
- package/docs/examples/account/get-prefs.md +3 -3
- package/docs/examples/account/get-session.md +3 -3
- package/docs/examples/account/get-sessions.md +3 -3
- package/docs/examples/account/get.md +3 -3
- package/docs/examples/account/update-email.md +3 -3
- package/docs/examples/account/update-name.md +3 -3
- package/docs/examples/account/update-password.md +3 -3
- package/docs/examples/account/update-phone-verification.md +20 -0
- package/docs/examples/{database/create-ip-attribute.md → account/update-phone.md} +4 -4
- package/docs/examples/account/update-prefs.md +3 -3
- package/docs/examples/account/update-recovery.md +3 -3
- package/docs/examples/account/update-session.md +3 -3
- package/docs/examples/account/update-status.md +3 -3
- package/docs/examples/account/update-verification.md +3 -3
- package/docs/examples/avatars/get-browser.md +3 -3
- package/docs/examples/avatars/get-credit-card.md +3 -3
- package/docs/examples/avatars/get-favicon.md +3 -3
- package/docs/examples/avatars/get-flag.md +3 -3
- package/docs/examples/avatars/get-image.md +3 -3
- package/docs/examples/avatars/get-initials.md +3 -3
- package/docs/examples/avatars/get-q-r.md +3 -3
- package/docs/examples/databases/create-boolean-attribute.md +20 -0
- package/docs/examples/{database → databases}/create-collection.md +3 -3
- package/docs/examples/databases/create-document.md +20 -0
- package/docs/examples/{database/create-boolean-attribute.md → databases/create-email-attribute.md} +3 -3
- package/docs/examples/databases/create-enum-attribute.md +20 -0
- package/docs/examples/databases/create-float-attribute.md +20 -0
- package/docs/examples/{database → databases}/create-index.md +3 -3
- package/docs/examples/{database → databases}/create-integer-attribute.md +3 -3
- package/docs/examples/{database/create-float-attribute.md → databases/create-ip-attribute.md} +3 -3
- package/docs/examples/{database → databases}/create-string-attribute.md +3 -3
- package/docs/examples/{database → databases}/create-url-attribute.md +3 -3
- package/docs/examples/{database/delete-attribute.md → databases/create.md} +3 -3
- package/docs/examples/databases/delete-attribute.md +20 -0
- package/docs/examples/databases/delete-collection.md +20 -0
- package/docs/examples/databases/delete-document.md +20 -0
- package/docs/examples/{database/create-email-attribute.md → databases/delete-index.md} +3 -3
- package/docs/examples/{database/delete-index.md → databases/delete.md} +3 -3
- package/docs/examples/databases/get-attribute.md +20 -0
- package/docs/examples/{database → databases}/get-collection.md +3 -3
- package/docs/examples/{database/delete-document.md → databases/get-document.md} +3 -3
- package/docs/examples/{database/create-enum-attribute.md → databases/get-index.md} +3 -3
- package/docs/examples/{database/get-index.md → databases/get.md} +3 -3
- package/docs/examples/{database → databases}/list-attributes.md +3 -3
- package/docs/examples/databases/list-collections.md +20 -0
- package/docs/examples/{database/create-document.md → databases/list-documents.md} +3 -3
- package/docs/examples/{database → databases}/list-indexes.md +3 -3
- package/docs/examples/{database/list-documents.md → databases/list.md} +3 -3
- package/docs/examples/{database → databases}/update-collection.md +3 -3
- package/docs/examples/{database → databases}/update-document.md +3 -3
- package/docs/examples/databases/update.md +20 -0
- package/docs/examples/functions/create-deployment.md +3 -3
- package/docs/examples/functions/create-execution.md +3 -3
- package/docs/examples/functions/create.md +3 -3
- package/docs/examples/functions/delete-deployment.md +3 -3
- package/docs/examples/functions/delete.md +3 -3
- package/docs/examples/functions/get-deployment.md +3 -3
- package/docs/examples/functions/get-execution.md +3 -3
- package/docs/examples/functions/get.md +3 -3
- package/docs/examples/functions/list-deployments.md +3 -3
- package/docs/examples/functions/list-executions.md +3 -3
- package/docs/examples/functions/list-runtimes.md +3 -3
- package/docs/examples/functions/list.md +3 -3
- package/docs/examples/functions/retry-build.md +3 -3
- package/docs/examples/functions/update-deployment.md +3 -3
- package/docs/examples/functions/update.md +3 -3
- package/docs/examples/health/get-antivirus.md +3 -3
- package/docs/examples/health/get-cache.md +3 -3
- package/docs/examples/health/get-d-b.md +3 -3
- package/docs/examples/health/get-queue-certificates.md +3 -3
- package/docs/examples/health/get-queue-functions.md +3 -3
- package/docs/examples/health/get-queue-logs.md +3 -3
- package/docs/examples/health/get-queue-webhooks.md +3 -3
- package/docs/examples/health/get-storage-local.md +3 -3
- package/docs/examples/health/get-time.md +3 -3
- package/docs/examples/health/get.md +3 -3
- package/docs/examples/locale/get-continents.md +3 -3
- package/docs/examples/locale/get-countries-e-u.md +3 -3
- package/docs/examples/locale/get-countries-phones.md +3 -3
- package/docs/examples/locale/get-countries.md +3 -3
- package/docs/examples/locale/get-currencies.md +3 -3
- package/docs/examples/locale/get-languages.md +3 -3
- package/docs/examples/locale/get.md +3 -3
- package/docs/examples/storage/create-bucket.md +3 -3
- package/docs/examples/storage/create-file.md +3 -3
- package/docs/examples/storage/delete-bucket.md +3 -3
- package/docs/examples/storage/delete-file.md +3 -3
- package/docs/examples/storage/get-bucket.md +3 -3
- package/docs/examples/storage/get-file-download.md +3 -3
- package/docs/examples/storage/get-file-preview.md +3 -3
- package/docs/examples/storage/get-file-view.md +3 -3
- package/docs/examples/storage/get-file.md +3 -3
- package/docs/examples/storage/list-buckets.md +3 -3
- package/docs/examples/storage/list-files.md +3 -3
- package/docs/examples/storage/update-bucket.md +3 -3
- package/docs/examples/storage/update-file.md +3 -3
- package/docs/examples/teams/create-membership.md +3 -3
- package/docs/examples/teams/create.md +3 -3
- package/docs/examples/teams/delete-membership.md +3 -3
- package/docs/examples/teams/delete.md +3 -3
- package/docs/examples/teams/get-membership.md +3 -3
- package/docs/examples/teams/get-memberships.md +3 -3
- package/docs/examples/teams/get.md +3 -3
- package/docs/examples/teams/list.md +3 -3
- package/docs/examples/teams/update-membership-roles.md +3 -3
- package/docs/examples/teams/update-membership-status.md +3 -3
- package/docs/examples/teams/update.md +3 -3
- package/docs/examples/users/create.md +3 -3
- package/docs/examples/users/delete-session.md +3 -3
- package/docs/examples/users/delete-sessions.md +3 -3
- package/docs/examples/users/delete.md +3 -3
- package/docs/examples/users/get-logs.md +3 -3
- package/docs/examples/users/get-memberships.md +3 -3
- package/docs/examples/users/get-prefs.md +3 -3
- package/docs/examples/users/get-sessions.md +3 -3
- package/docs/examples/users/get.md +3 -3
- package/docs/examples/users/list.md +3 -3
- package/docs/examples/{database/get-attribute.md → users/update-email-verification.md} +3 -3
- package/docs/examples/users/update-email.md +3 -3
- package/docs/examples/users/update-name.md +3 -3
- package/docs/examples/users/update-password.md +3 -3
- package/docs/examples/{database/delete-collection.md → users/update-phone-verification.md} +3 -3
- package/docs/examples/{database/list-collections.md → users/update-phone.md} +3 -3
- package/docs/examples/users/update-prefs.md +3 -3
- package/docs/examples/users/update-status.md +3 -3
- package/index.d.ts +288 -97
- package/index.js +4 -2
- package/lib/client.js +9 -3
- package/lib/inputFile.js +47 -0
- package/lib/services/account.js +103 -2
- package/lib/services/avatars.js +2 -0
- package/lib/services/{database.js → databases.js} +183 -87
- package/lib/services/functions.js +99 -41
- package/lib/services/health.js +2 -0
- package/lib/services/locale.js +2 -0
- package/lib/services/storage.js +108 -50
- package/lib/services/teams.js +2 -0
- package/lib/services/users.js +65 -1
- package/package.json +1 -1
- package/docs/examples/database/get-document.md +0 -20
- package/docs/examples/users/update-verification.md +0 -20
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
const Service = require('../service.js');
|
|
2
2
|
const AppwriteException = require('../exception.js');
|
|
3
|
+
const InputFile = require('../inputFile.js');
|
|
3
4
|
const client = require('../client.js');
|
|
5
|
+
const Stream = require('stream');
|
|
4
6
|
const { promisify } = require('util');
|
|
5
7
|
const fs = require('fs');
|
|
6
8
|
|
|
@@ -319,7 +321,7 @@ class Functions extends Service {
|
|
|
319
321
|
*
|
|
320
322
|
* @param {string} functionId
|
|
321
323
|
* @param {string} entrypoint
|
|
322
|
-
* @param {
|
|
324
|
+
* @param {InputFile} code
|
|
323
325
|
* @param {boolean} activate
|
|
324
326
|
* @throws {AppwriteException}
|
|
325
327
|
* @returns {Promise}
|
|
@@ -349,68 +351,124 @@ class Functions extends Service {
|
|
|
349
351
|
}
|
|
350
352
|
|
|
351
353
|
if (typeof code !== 'undefined') {
|
|
352
|
-
payload['code'] = code
|
|
354
|
+
payload['code'] = code;
|
|
353
355
|
}
|
|
354
356
|
|
|
355
357
|
if (typeof activate !== 'undefined') {
|
|
356
358
|
payload['activate'] = activate.toString();
|
|
357
359
|
}
|
|
358
360
|
|
|
359
|
-
const
|
|
361
|
+
const size = code.size;
|
|
360
362
|
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
} else {
|
|
368
|
-
let id = undefined;
|
|
369
|
-
let response = undefined;
|
|
363
|
+
const headers = {
|
|
364
|
+
'content-type': 'multipart/form-data',
|
|
365
|
+
};
|
|
366
|
+
|
|
367
|
+
let id = undefined;
|
|
368
|
+
let response = undefined;
|
|
370
369
|
|
|
371
|
-
|
|
372
|
-
const totalCounters = Math.ceil(size / client.CHUNK_SIZE);
|
|
370
|
+
let chunksUploaded = 0;
|
|
373
371
|
|
|
374
|
-
const headers = {
|
|
375
|
-
'content-type': 'multipart/form-data',
|
|
376
|
-
};
|
|
377
372
|
|
|
373
|
+
let currentChunk = Buffer.from('');
|
|
374
|
+
let currentChunkSize = 0;
|
|
375
|
+
let currentChunkStart = 0;
|
|
378
376
|
|
|
379
|
-
|
|
380
|
-
const start = (counter * client.CHUNK_SIZE);
|
|
381
|
-
const end = Math.min((((counter * client.CHUNK_SIZE) + client.CHUNK_SIZE) - 1), size);
|
|
377
|
+
const selfClient = this.client;
|
|
382
378
|
|
|
379
|
+
async function uploadChunk(lastUpload = false) {
|
|
380
|
+
if(chunksUploaded - 1 >= currentChunkStart / client.CHUNK_SIZE) {
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
const start = currentChunkStart;
|
|
385
|
+
const end = Math.min(((start + client.CHUNK_SIZE) - 1), size);
|
|
386
|
+
|
|
387
|
+
if(!lastUpload || currentChunkStart !== 0) {
|
|
383
388
|
headers['content-range'] = 'bytes ' + start + '-' + end + '/' + size;
|
|
389
|
+
}
|
|
384
390
|
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
391
|
+
if (id) {
|
|
392
|
+
headers['x-appwrite-id'] = id;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
const stream = Stream.Readable.from(currentChunk);
|
|
396
|
+
payload['code'] = { type: 'file', file: stream, filename: code.filename };
|
|
388
397
|
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
398
|
+
response = await selfClient.call('post', path, headers, payload);
|
|
399
|
+
|
|
400
|
+
if (!id) {
|
|
401
|
+
id = response['$id'];
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
if (onProgress !== null) {
|
|
405
|
+
onProgress({
|
|
406
|
+
$id: response['$id'],
|
|
407
|
+
progress: Math.min((start+client.CHUNK_SIZE) * client.CHUNK_SIZE, size) / size * 100,
|
|
408
|
+
sizeUploaded: end+1,
|
|
409
|
+
chunksTotal: response['chunksTotal'],
|
|
410
|
+
chunksUploaded: response['chunksUploaded']
|
|
392
411
|
});
|
|
393
|
-
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
currentChunkStart += client.CHUNK_SIZE;
|
|
415
|
+
}
|
|
394
416
|
|
|
395
|
-
|
|
417
|
+
return await new Promise((resolve, reject) => {
|
|
418
|
+
const writeStream = new Stream.Writable();
|
|
419
|
+
writeStream._write = async (mainChunk, encoding, next) => {
|
|
420
|
+
// Segment incoming chunk into up to 5MB chunks
|
|
421
|
+
const mainChunkSize = Buffer.byteLength(mainChunk);
|
|
422
|
+
const chunksCount = Math.ceil(mainChunkSize / client.CHUNK_SIZE);
|
|
423
|
+
const chunks = [];
|
|
396
424
|
|
|
397
|
-
|
|
398
|
-
|
|
425
|
+
for(let i = 0; i < chunksCount; i++) {
|
|
426
|
+
const chunk = mainChunk.slice(i * client.CHUNK_SIZE, client.CHUNK_SIZE);
|
|
427
|
+
chunks.push(chunk);
|
|
399
428
|
}
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
429
|
+
|
|
430
|
+
for (const chunk of chunks) {
|
|
431
|
+
const chunkSize = Buffer.byteLength(chunk);
|
|
432
|
+
|
|
433
|
+
if(chunkSize + currentChunkSize == client.CHUNK_SIZE) {
|
|
434
|
+
// Upload chunk
|
|
435
|
+
currentChunk = Buffer.concat([currentChunk, chunk]);
|
|
436
|
+
await uploadChunk();
|
|
437
|
+
currentChunk = Buffer.from('');
|
|
438
|
+
currentChunkSize = 0;
|
|
439
|
+
} else if(chunkSize + currentChunkSize > client.CHUNK_SIZE) {
|
|
440
|
+
// Upload chunk, put rest into next chunk
|
|
441
|
+
const bytesToUpload = client.CHUNK_SIZE - currentChunkSize;
|
|
442
|
+
const newChunkSection = chunk.slice(0, bytesToUpload);
|
|
443
|
+
currentChunk = Buffer.concat([currentChunk, newChunkSection]);
|
|
444
|
+
currentChunkSize = Buffer.byteLength(currentChunk);
|
|
445
|
+
await uploadChunk();
|
|
446
|
+
currentChunk = chunk.slice(bytesToUpload, undefined);
|
|
447
|
+
currentChunkSize = chunkSize - bytesToUpload;
|
|
448
|
+
} else {
|
|
449
|
+
// Append into current chunk
|
|
450
|
+
currentChunk = Buffer.concat([currentChunk, chunk]);
|
|
451
|
+
currentChunkSize = chunkSize + currentChunkSize;
|
|
452
|
+
}
|
|
409
453
|
}
|
|
454
|
+
|
|
455
|
+
next();
|
|
410
456
|
}
|
|
411
457
|
|
|
412
|
-
|
|
413
|
-
|
|
458
|
+
writeStream.on("finish", async () => {
|
|
459
|
+
if(currentChunkSize > 0) {
|
|
460
|
+
await uploadChunk(true);
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
resolve(response);
|
|
464
|
+
});
|
|
465
|
+
|
|
466
|
+
writeStream.on("error", (err) => {
|
|
467
|
+
reject(err);
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
code.stream.pipe(writeStream);
|
|
471
|
+
});
|
|
414
472
|
}
|
|
415
473
|
|
|
416
474
|
/**
|
package/lib/services/health.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
const Service = require('../service.js');
|
|
2
2
|
const AppwriteException = require('../exception.js');
|
|
3
|
+
const InputFile = require('../inputFile.js');
|
|
3
4
|
const client = require('../client.js');
|
|
5
|
+
const Stream = require('stream');
|
|
4
6
|
const { promisify } = require('util');
|
|
5
7
|
const fs = require('fs');
|
|
6
8
|
|
package/lib/services/locale.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
const Service = require('../service.js');
|
|
2
2
|
const AppwriteException = require('../exception.js');
|
|
3
|
+
const InputFile = require('../inputFile.js');
|
|
3
4
|
const client = require('../client.js');
|
|
5
|
+
const Stream = require('stream');
|
|
4
6
|
const { promisify } = require('util');
|
|
5
7
|
const fs = require('fs');
|
|
6
8
|
|
package/lib/services/storage.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
const Service = require('../service.js');
|
|
2
2
|
const AppwriteException = require('../exception.js');
|
|
3
|
+
const InputFile = require('../inputFile.js');
|
|
3
4
|
const client = require('../client.js');
|
|
5
|
+
const Stream = require('stream');
|
|
4
6
|
const { promisify } = require('util');
|
|
5
7
|
const fs = require('fs');
|
|
6
8
|
|
|
@@ -331,7 +333,7 @@ class Storage extends Service {
|
|
|
331
333
|
*
|
|
332
334
|
* @param {string} bucketId
|
|
333
335
|
* @param {string} fileId
|
|
334
|
-
* @param {
|
|
336
|
+
* @param {InputFile} file
|
|
335
337
|
* @param {string[]} read
|
|
336
338
|
* @param {string[]} write
|
|
337
339
|
* @throws {AppwriteException}
|
|
@@ -358,7 +360,7 @@ class Storage extends Service {
|
|
|
358
360
|
}
|
|
359
361
|
|
|
360
362
|
if (typeof file !== 'undefined') {
|
|
361
|
-
payload['file'] = file
|
|
363
|
+
payload['file'] = file;
|
|
362
364
|
}
|
|
363
365
|
|
|
364
366
|
if (typeof read !== 'undefined') {
|
|
@@ -369,68 +371,124 @@ class Storage extends Service {
|
|
|
369
371
|
payload['write'] = write;
|
|
370
372
|
}
|
|
371
373
|
|
|
372
|
-
const
|
|
374
|
+
const size = file.size;
|
|
373
375
|
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
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
|
-
}
|
|
376
|
+
const headers = {
|
|
377
|
+
'content-type': 'multipart/form-data',
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
let id = undefined;
|
|
381
|
+
let response = undefined;
|
|
382
|
+
|
|
383
|
+
let chunksUploaded = 0;
|
|
384
|
+
|
|
385
|
+
if(fileId != 'unique()') {
|
|
386
|
+
try {
|
|
387
|
+
response = await this.client.call('get', path + '/' + fileId, headers);
|
|
388
|
+
chunksUploaded = response.chunksUploaded;
|
|
389
|
+
} catch(e) {
|
|
397
390
|
}
|
|
391
|
+
}
|
|
398
392
|
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
393
|
+
let currentChunk = Buffer.from('');
|
|
394
|
+
let currentChunkSize = 0;
|
|
395
|
+
let currentChunkStart = 0;
|
|
402
396
|
|
|
397
|
+
const selfClient = this.client;
|
|
398
|
+
|
|
399
|
+
async function uploadChunk(lastUpload = false) {
|
|
400
|
+
if(chunksUploaded - 1 >= currentChunkStart / client.CHUNK_SIZE) {
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
const start = currentChunkStart;
|
|
405
|
+
const end = Math.min(((start + client.CHUNK_SIZE) - 1), size);
|
|
406
|
+
|
|
407
|
+
if(!lastUpload || currentChunkStart !== 0) {
|
|
403
408
|
headers['content-range'] = 'bytes ' + start + '-' + end + '/' + size;
|
|
409
|
+
}
|
|
404
410
|
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
411
|
+
if (id) {
|
|
412
|
+
headers['x-appwrite-id'] = id;
|
|
413
|
+
}
|
|
408
414
|
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
415
|
+
const stream = Stream.Readable.from(currentChunk);
|
|
416
|
+
payload['file'] = { type: 'file', file: stream, filename: file.filename };
|
|
417
|
+
|
|
418
|
+
response = await selfClient.call('post', path, headers, payload);
|
|
419
|
+
|
|
420
|
+
if (!id) {
|
|
421
|
+
id = response['$id'];
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
if (onProgress !== null) {
|
|
425
|
+
onProgress({
|
|
426
|
+
$id: response['$id'],
|
|
427
|
+
progress: Math.min((start+client.CHUNK_SIZE) * client.CHUNK_SIZE, size) / size * 100,
|
|
428
|
+
sizeUploaded: end+1,
|
|
429
|
+
chunksTotal: response['chunksTotal'],
|
|
430
|
+
chunksUploaded: response['chunksUploaded']
|
|
412
431
|
});
|
|
413
|
-
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
currentChunkStart += client.CHUNK_SIZE;
|
|
435
|
+
}
|
|
414
436
|
|
|
415
|
-
|
|
437
|
+
return await new Promise((resolve, reject) => {
|
|
438
|
+
const writeStream = new Stream.Writable();
|
|
439
|
+
writeStream._write = async (mainChunk, encoding, next) => {
|
|
440
|
+
// Segment incoming chunk into up to 5MB chunks
|
|
441
|
+
const mainChunkSize = Buffer.byteLength(mainChunk);
|
|
442
|
+
const chunksCount = Math.ceil(mainChunkSize / client.CHUNK_SIZE);
|
|
443
|
+
const chunks = [];
|
|
416
444
|
|
|
417
|
-
|
|
418
|
-
|
|
445
|
+
for(let i = 0; i < chunksCount; i++) {
|
|
446
|
+
const chunk = mainChunk.slice(i * client.CHUNK_SIZE, client.CHUNK_SIZE);
|
|
447
|
+
chunks.push(chunk);
|
|
419
448
|
}
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
449
|
+
|
|
450
|
+
for (const chunk of chunks) {
|
|
451
|
+
const chunkSize = Buffer.byteLength(chunk);
|
|
452
|
+
|
|
453
|
+
if(chunkSize + currentChunkSize == client.CHUNK_SIZE) {
|
|
454
|
+
// Upload chunk
|
|
455
|
+
currentChunk = Buffer.concat([currentChunk, chunk]);
|
|
456
|
+
await uploadChunk();
|
|
457
|
+
currentChunk = Buffer.from('');
|
|
458
|
+
currentChunkSize = 0;
|
|
459
|
+
} else if(chunkSize + currentChunkSize > client.CHUNK_SIZE) {
|
|
460
|
+
// Upload chunk, put rest into next chunk
|
|
461
|
+
const bytesToUpload = client.CHUNK_SIZE - currentChunkSize;
|
|
462
|
+
const newChunkSection = chunk.slice(0, bytesToUpload);
|
|
463
|
+
currentChunk = Buffer.concat([currentChunk, newChunkSection]);
|
|
464
|
+
currentChunkSize = Buffer.byteLength(currentChunk);
|
|
465
|
+
await uploadChunk();
|
|
466
|
+
currentChunk = chunk.slice(bytesToUpload, undefined);
|
|
467
|
+
currentChunkSize = chunkSize - bytesToUpload;
|
|
468
|
+
} else {
|
|
469
|
+
// Append into current chunk
|
|
470
|
+
currentChunk = Buffer.concat([currentChunk, chunk]);
|
|
471
|
+
currentChunkSize = chunkSize + currentChunkSize;
|
|
472
|
+
}
|
|
429
473
|
}
|
|
474
|
+
|
|
475
|
+
next();
|
|
430
476
|
}
|
|
431
477
|
|
|
432
|
-
|
|
433
|
-
|
|
478
|
+
writeStream.on("finish", async () => {
|
|
479
|
+
if(currentChunkSize > 0) {
|
|
480
|
+
await uploadChunk(true);
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
resolve(response);
|
|
484
|
+
});
|
|
485
|
+
|
|
486
|
+
writeStream.on("error", (err) => {
|
|
487
|
+
reject(err);
|
|
488
|
+
});
|
|
489
|
+
|
|
490
|
+
file.stream.pipe(writeStream);
|
|
491
|
+
});
|
|
434
492
|
}
|
|
435
493
|
|
|
436
494
|
/**
|
package/lib/services/teams.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
const Service = require('../service.js');
|
|
2
2
|
const AppwriteException = require('../exception.js');
|
|
3
|
+
const InputFile = require('../inputFile.js');
|
|
3
4
|
const client = require('../client.js');
|
|
5
|
+
const Stream = require('stream');
|
|
4
6
|
const { promisify } = require('util');
|
|
5
7
|
const fs = require('fs');
|
|
6
8
|
|
package/lib/services/users.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
const Service = require('../service.js');
|
|
2
2
|
const AppwriteException = require('../exception.js');
|
|
3
|
+
const InputFile = require('../inputFile.js');
|
|
3
4
|
const client = require('../client.js');
|
|
5
|
+
const Stream = require('stream');
|
|
4
6
|
const { promisify } = require('util');
|
|
5
7
|
const fs = require('fs');
|
|
6
8
|
|
|
@@ -298,6 +300,37 @@ class Users extends Service {
|
|
|
298
300
|
}, payload);
|
|
299
301
|
}
|
|
300
302
|
|
|
303
|
+
/**
|
|
304
|
+
* Update Phone
|
|
305
|
+
*
|
|
306
|
+
* Update the user phone by its unique ID.
|
|
307
|
+
*
|
|
308
|
+
* @param {string} userId
|
|
309
|
+
* @param {string} number
|
|
310
|
+
* @throws {AppwriteException}
|
|
311
|
+
* @returns {Promise}
|
|
312
|
+
*/
|
|
313
|
+
async updatePhone(userId, number) {
|
|
314
|
+
if (typeof userId === 'undefined') {
|
|
315
|
+
throw new AppwriteException('Missing required parameter: "userId"');
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
if (typeof number === 'undefined') {
|
|
319
|
+
throw new AppwriteException('Missing required parameter: "number"');
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
let path = '/users/{userId}/phone'.replace('{userId}', userId);
|
|
323
|
+
let payload = {};
|
|
324
|
+
|
|
325
|
+
if (typeof number !== 'undefined') {
|
|
326
|
+
payload['number'] = number;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
return await this.client.call('patch', path, {
|
|
330
|
+
'content-type': 'application/json',
|
|
331
|
+
}, payload);
|
|
332
|
+
}
|
|
333
|
+
|
|
301
334
|
/**
|
|
302
335
|
* Get User Preferences
|
|
303
336
|
*
|
|
@@ -466,7 +499,7 @@ class Users extends Service {
|
|
|
466
499
|
* @throws {AppwriteException}
|
|
467
500
|
* @returns {Promise}
|
|
468
501
|
*/
|
|
469
|
-
async
|
|
502
|
+
async updateEmailVerification(userId, emailVerification) {
|
|
470
503
|
if (typeof userId === 'undefined') {
|
|
471
504
|
throw new AppwriteException('Missing required parameter: "userId"');
|
|
472
505
|
}
|
|
@@ -486,6 +519,37 @@ class Users extends Service {
|
|
|
486
519
|
'content-type': 'application/json',
|
|
487
520
|
}, payload);
|
|
488
521
|
}
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
* Update Phone Verification
|
|
525
|
+
*
|
|
526
|
+
* Update the user phone verification status by its unique ID.
|
|
527
|
+
*
|
|
528
|
+
* @param {string} userId
|
|
529
|
+
* @param {boolean} phoneVerification
|
|
530
|
+
* @throws {AppwriteException}
|
|
531
|
+
* @returns {Promise}
|
|
532
|
+
*/
|
|
533
|
+
async updatePhoneVerification(userId, phoneVerification) {
|
|
534
|
+
if (typeof userId === 'undefined') {
|
|
535
|
+
throw new AppwriteException('Missing required parameter: "userId"');
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
if (typeof phoneVerification === 'undefined') {
|
|
539
|
+
throw new AppwriteException('Missing required parameter: "phoneVerification"');
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
let path = '/users/{userId}/verification/phone'.replace('{userId}', userId);
|
|
543
|
+
let payload = {};
|
|
544
|
+
|
|
545
|
+
if (typeof phoneVerification !== 'undefined') {
|
|
546
|
+
payload['phoneVerification'] = phoneVerification;
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
return await this.client.call('patch', path, {
|
|
550
|
+
'content-type': 'application/json',
|
|
551
|
+
}, payload);
|
|
552
|
+
}
|
|
489
553
|
}
|
|
490
554
|
|
|
491
555
|
module.exports = Users;
|
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
|
+
"version": "7.0.2",
|
|
6
6
|
"license": "BSD-3-Clause",
|
|
7
7
|
"main": "./index.js",
|
|
8
8
|
"types": "./index.d.ts",
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
const sdk = require('node-appwrite');
|
|
2
|
-
|
|
3
|
-
// Init SDK
|
|
4
|
-
let client = new sdk.Client();
|
|
5
|
-
|
|
6
|
-
let database = new sdk.Database(client);
|
|
7
|
-
|
|
8
|
-
client
|
|
9
|
-
.setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
|
|
10
|
-
.setProject('5df5acd0d48c2') // Your project ID
|
|
11
|
-
.setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
|
|
12
|
-
;
|
|
13
|
-
|
|
14
|
-
let promise = database.getDocument('[COLLECTION_ID]', '[DOCUMENT_ID]');
|
|
15
|
-
|
|
16
|
-
promise.then(function (response) {
|
|
17
|
-
console.log(response);
|
|
18
|
-
}, function (error) {
|
|
19
|
-
console.log(error);
|
|
20
|
-
});
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
const sdk = require('node-appwrite');
|
|
2
|
-
|
|
3
|
-
// Init SDK
|
|
4
|
-
let client = new sdk.Client();
|
|
5
|
-
|
|
6
|
-
let users = new sdk.Users(client);
|
|
7
|
-
|
|
8
|
-
client
|
|
9
|
-
.setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
|
|
10
|
-
.setProject('5df5acd0d48c2') // Your project ID
|
|
11
|
-
.setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
|
|
12
|
-
;
|
|
13
|
-
|
|
14
|
-
let promise = users.updateVerification('[USER_ID]', false);
|
|
15
|
-
|
|
16
|
-
promise.then(function (response) {
|
|
17
|
-
console.log(response);
|
|
18
|
-
}, function (error) {
|
|
19
|
-
console.log(error);
|
|
20
|
-
});
|