react-native-appwrite 0.9.2 → 0.10.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/CHANGELOG.md +13 -0
- package/README.md +1 -1
- package/dist/cjs/sdk.js +241 -20
- package/dist/cjs/sdk.js.map +1 -1
- package/dist/esm/sdk.js +241 -20
- package/dist/esm/sdk.js.map +1 -1
- package/package.json +1 -1
- package/src/client.ts +4 -2
- package/src/services/avatars.ts +296 -20
- package/src/services/storage.ts +140 -8
- package/types/client.d.ts +1 -1
- package/types/services/avatars.d.ts +136 -7
- package/types/services/storage.d.ts +52 -3
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "react-native-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": "0.
|
|
5
|
+
"version": "0.10.0",
|
|
6
6
|
"license": "BSD-3-Clause",
|
|
7
7
|
"main": "dist/cjs/sdk.js",
|
|
8
8
|
"exports": {
|
package/src/client.ts
CHANGED
|
@@ -115,7 +115,7 @@ class Client {
|
|
|
115
115
|
'x-sdk-name': 'React Native',
|
|
116
116
|
'x-sdk-platform': 'client',
|
|
117
117
|
'x-sdk-language': 'reactnative',
|
|
118
|
-
'x-sdk-version': '0.
|
|
118
|
+
'x-sdk-version': '0.10.0',
|
|
119
119
|
'X-Appwrite-Response-Format': '1.7.0',
|
|
120
120
|
};
|
|
121
121
|
|
|
@@ -432,7 +432,7 @@ class Client {
|
|
|
432
432
|
}
|
|
433
433
|
}
|
|
434
434
|
|
|
435
|
-
async call(method: string, url: URL, headers: Headers = {}, params: Payload = {}): Promise<any> {
|
|
435
|
+
async call(method: string, url: URL, headers: Headers = {}, params: Payload = {}, responseType = 'json'): Promise<any> {
|
|
436
436
|
method = method.toUpperCase();
|
|
437
437
|
|
|
438
438
|
headers = Object.assign({}, this.headers, headers);
|
|
@@ -488,6 +488,8 @@ class Client {
|
|
|
488
488
|
|
|
489
489
|
if (response.headers.get('content-type')?.includes('application/json')) {
|
|
490
490
|
data = await response.json();
|
|
491
|
+
} else if (responseType === 'arrayBuffer') {
|
|
492
|
+
data = await response.arrayBuffer();
|
|
491
493
|
} else {
|
|
492
494
|
data = {
|
|
493
495
|
message: await response.text()
|
package/src/services/avatars.ts
CHANGED
|
@@ -33,9 +33,9 @@ export class Avatars extends Service {
|
|
|
33
33
|
* @param {number} height
|
|
34
34
|
* @param {number} quality
|
|
35
35
|
* @throws {AppwriteException}
|
|
36
|
-
* @returns {
|
|
36
|
+
* @returns {ArrayBuffer}
|
|
37
37
|
*/
|
|
38
|
-
getBrowser(code: Browser, width?: number, height?: number, quality?: number):
|
|
38
|
+
getBrowser(code: Browser, width?: number, height?: number, quality?: number): Promise<ArrayBuffer> {
|
|
39
39
|
if (typeof code === 'undefined') {
|
|
40
40
|
throw new AppwriteException('Missing required parameter: "code"');
|
|
41
41
|
}
|
|
@@ -62,7 +62,8 @@ export class Avatars extends Service {
|
|
|
62
62
|
for (const [key, value] of Object.entries(Service.flatten(payload))) {
|
|
63
63
|
uri.searchParams.append(key, value);
|
|
64
64
|
}
|
|
65
|
-
return uri
|
|
65
|
+
return this.client.call('get', uri, {
|
|
66
|
+
}, payload, 'arrayBuffer');
|
|
66
67
|
}
|
|
67
68
|
|
|
68
69
|
/**
|
|
@@ -81,9 +82,9 @@ export class Avatars extends Service {
|
|
|
81
82
|
* @param {number} height
|
|
82
83
|
* @param {number} quality
|
|
83
84
|
* @throws {AppwriteException}
|
|
84
|
-
* @returns {
|
|
85
|
+
* @returns {ArrayBuffer}
|
|
85
86
|
*/
|
|
86
|
-
getCreditCard(code: CreditCard, width?: number, height?: number, quality?: number):
|
|
87
|
+
getCreditCard(code: CreditCard, width?: number, height?: number, quality?: number): Promise<ArrayBuffer> {
|
|
87
88
|
if (typeof code === 'undefined') {
|
|
88
89
|
throw new AppwriteException('Missing required parameter: "code"');
|
|
89
90
|
}
|
|
@@ -110,7 +111,8 @@ export class Avatars extends Service {
|
|
|
110
111
|
for (const [key, value] of Object.entries(Service.flatten(payload))) {
|
|
111
112
|
uri.searchParams.append(key, value);
|
|
112
113
|
}
|
|
113
|
-
return uri
|
|
114
|
+
return this.client.call('get', uri, {
|
|
115
|
+
}, payload, 'arrayBuffer');
|
|
114
116
|
}
|
|
115
117
|
|
|
116
118
|
/**
|
|
@@ -121,9 +123,9 @@ export class Avatars extends Service {
|
|
|
121
123
|
*
|
|
122
124
|
* @param {string} url
|
|
123
125
|
* @throws {AppwriteException}
|
|
124
|
-
* @returns {
|
|
126
|
+
* @returns {ArrayBuffer}
|
|
125
127
|
*/
|
|
126
|
-
getFavicon(url: string):
|
|
128
|
+
getFavicon(url: string): Promise<ArrayBuffer> {
|
|
127
129
|
if (typeof url === 'undefined') {
|
|
128
130
|
throw new AppwriteException('Missing required parameter: "url"');
|
|
129
131
|
}
|
|
@@ -142,7 +144,8 @@ export class Avatars extends Service {
|
|
|
142
144
|
for (const [key, value] of Object.entries(Service.flatten(payload))) {
|
|
143
145
|
uri.searchParams.append(key, value);
|
|
144
146
|
}
|
|
145
|
-
return uri
|
|
147
|
+
return this.client.call('get', uri, {
|
|
148
|
+
}, payload, 'arrayBuffer');
|
|
146
149
|
}
|
|
147
150
|
|
|
148
151
|
/**
|
|
@@ -162,9 +165,9 @@ export class Avatars extends Service {
|
|
|
162
165
|
* @param {number} height
|
|
163
166
|
* @param {number} quality
|
|
164
167
|
* @throws {AppwriteException}
|
|
165
|
-
* @returns {
|
|
168
|
+
* @returns {ArrayBuffer}
|
|
166
169
|
*/
|
|
167
|
-
getFlag(code: Flag, width?: number, height?: number, quality?: number):
|
|
170
|
+
getFlag(code: Flag, width?: number, height?: number, quality?: number): Promise<ArrayBuffer> {
|
|
168
171
|
if (typeof code === 'undefined') {
|
|
169
172
|
throw new AppwriteException('Missing required parameter: "code"');
|
|
170
173
|
}
|
|
@@ -191,7 +194,8 @@ export class Avatars extends Service {
|
|
|
191
194
|
for (const [key, value] of Object.entries(Service.flatten(payload))) {
|
|
192
195
|
uri.searchParams.append(key, value);
|
|
193
196
|
}
|
|
194
|
-
return uri
|
|
197
|
+
return this.client.call('get', uri, {
|
|
198
|
+
}, payload, 'arrayBuffer');
|
|
195
199
|
}
|
|
196
200
|
|
|
197
201
|
/**
|
|
@@ -211,9 +215,9 @@ export class Avatars extends Service {
|
|
|
211
215
|
* @param {number} width
|
|
212
216
|
* @param {number} height
|
|
213
217
|
* @throws {AppwriteException}
|
|
214
|
-
* @returns {
|
|
218
|
+
* @returns {ArrayBuffer}
|
|
215
219
|
*/
|
|
216
|
-
getImage(url: string, width?: number, height?: number):
|
|
220
|
+
getImage(url: string, width?: number, height?: number): Promise<ArrayBuffer> {
|
|
217
221
|
if (typeof url === 'undefined') {
|
|
218
222
|
throw new AppwriteException('Missing required parameter: "url"');
|
|
219
223
|
}
|
|
@@ -240,7 +244,8 @@ export class Avatars extends Service {
|
|
|
240
244
|
for (const [key, value] of Object.entries(Service.flatten(payload))) {
|
|
241
245
|
uri.searchParams.append(key, value);
|
|
242
246
|
}
|
|
243
|
-
return uri
|
|
247
|
+
return this.client.call('get', uri, {
|
|
248
|
+
}, payload, 'arrayBuffer');
|
|
244
249
|
}
|
|
245
250
|
|
|
246
251
|
/**
|
|
@@ -266,9 +271,9 @@ export class Avatars extends Service {
|
|
|
266
271
|
* @param {number} height
|
|
267
272
|
* @param {string} background
|
|
268
273
|
* @throws {AppwriteException}
|
|
269
|
-
* @returns {
|
|
274
|
+
* @returns {ArrayBuffer}
|
|
270
275
|
*/
|
|
271
|
-
getInitials(name?: string, width?: number, height?: number, background?: string):
|
|
276
|
+
getInitials(name?: string, width?: number, height?: number, background?: string): Promise<ArrayBuffer> {
|
|
272
277
|
const apiPath = '/avatars/initials';
|
|
273
278
|
const payload: Payload = {};
|
|
274
279
|
|
|
@@ -295,7 +300,8 @@ export class Avatars extends Service {
|
|
|
295
300
|
for (const [key, value] of Object.entries(Service.flatten(payload))) {
|
|
296
301
|
uri.searchParams.append(key, value);
|
|
297
302
|
}
|
|
298
|
-
return uri
|
|
303
|
+
return this.client.call('get', uri, {
|
|
304
|
+
}, payload, 'arrayBuffer');
|
|
299
305
|
}
|
|
300
306
|
|
|
301
307
|
/**
|
|
@@ -308,9 +314,9 @@ export class Avatars extends Service {
|
|
|
308
314
|
* @param {number} margin
|
|
309
315
|
* @param {boolean} download
|
|
310
316
|
* @throws {AppwriteException}
|
|
311
|
-
* @returns {
|
|
317
|
+
* @returns {ArrayBuffer}
|
|
312
318
|
*/
|
|
313
|
-
getQR(text: string, size?: number, margin?: number, download?: boolean):
|
|
319
|
+
getQR(text: string, size?: number, margin?: number, download?: boolean): Promise<ArrayBuffer> {
|
|
314
320
|
if (typeof text === 'undefined') {
|
|
315
321
|
throw new AppwriteException('Missing required parameter: "text"');
|
|
316
322
|
}
|
|
@@ -341,6 +347,276 @@ export class Avatars extends Service {
|
|
|
341
347
|
for (const [key, value] of Object.entries(Service.flatten(payload))) {
|
|
342
348
|
uri.searchParams.append(key, value);
|
|
343
349
|
}
|
|
350
|
+
return this.client.call('get', uri, {
|
|
351
|
+
}, payload, 'arrayBuffer');
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* You can use this endpoint to show different browser icons to your users.
|
|
356
|
+
* The code argument receives the browser code as it appears in your user [GET
|
|
357
|
+
* /account/sessions](https://appwrite.io/docs/references/cloud/client-web/account#getSessions)
|
|
358
|
+
* endpoint. Use width, height and quality arguments to change the output
|
|
359
|
+
* settings.
|
|
360
|
+
*
|
|
361
|
+
* When one dimension is specified and the other is 0, the image is scaled
|
|
362
|
+
* with preserved aspect ratio. If both dimensions are 0, the API provides an
|
|
363
|
+
* image at source quality. If dimensions are not specified, the default size
|
|
364
|
+
* of image returned is 100x100px.
|
|
365
|
+
*
|
|
366
|
+
* @param {Browser} code
|
|
367
|
+
* @param {number} width
|
|
368
|
+
* @param {number} height
|
|
369
|
+
* @param {number} quality
|
|
370
|
+
* @throws {AppwriteException}
|
|
371
|
+
* @returns {URL}
|
|
372
|
+
*/
|
|
373
|
+
getBrowserURL(code: Browser, width?: number, height?: number, quality?: number): URL {
|
|
374
|
+
const apiPath = '/avatars/browsers/{code}'.replace('{code}', code);
|
|
375
|
+
const payload: Payload = {};
|
|
376
|
+
|
|
377
|
+
if (typeof width !== 'undefined') {
|
|
378
|
+
payload['width'] = width;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
if (typeof height !== 'undefined') {
|
|
382
|
+
payload['height'] = height;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
if (typeof quality !== 'undefined') {
|
|
386
|
+
payload['quality'] = quality;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
const uri = new URL(this.client.config.endpoint + apiPath);
|
|
390
|
+
|
|
391
|
+
return uri;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* The credit card endpoint will return you the icon of the credit card
|
|
396
|
+
* provider you need. Use width, height and quality arguments to change the
|
|
397
|
+
* output settings.
|
|
398
|
+
*
|
|
399
|
+
* When one dimension is specified and the other is 0, the image is scaled
|
|
400
|
+
* with preserved aspect ratio. If both dimensions are 0, the API provides an
|
|
401
|
+
* image at source quality. If dimensions are not specified, the default size
|
|
402
|
+
* of image returned is 100x100px.
|
|
403
|
+
*
|
|
404
|
+
*
|
|
405
|
+
* @param {CreditCard} code
|
|
406
|
+
* @param {number} width
|
|
407
|
+
* @param {number} height
|
|
408
|
+
* @param {number} quality
|
|
409
|
+
* @throws {AppwriteException}
|
|
410
|
+
* @returns {URL}
|
|
411
|
+
*/
|
|
412
|
+
getCreditCardURL(code: CreditCard, width?: number, height?: number, quality?: number): URL {
|
|
413
|
+
const apiPath = '/avatars/credit-cards/{code}'.replace('{code}', code);
|
|
414
|
+
const payload: Payload = {};
|
|
415
|
+
|
|
416
|
+
if (typeof width !== 'undefined') {
|
|
417
|
+
payload['width'] = width;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
if (typeof height !== 'undefined') {
|
|
421
|
+
payload['height'] = height;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
if (typeof quality !== 'undefined') {
|
|
425
|
+
payload['quality'] = quality;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
const uri = new URL(this.client.config.endpoint + apiPath);
|
|
429
|
+
|
|
430
|
+
return uri;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* Use this endpoint to fetch the favorite icon (AKA favicon) of any remote
|
|
435
|
+
* website URL.
|
|
436
|
+
*
|
|
437
|
+
* This endpoint does not follow HTTP redirects.
|
|
438
|
+
*
|
|
439
|
+
* @param {string} url
|
|
440
|
+
* @throws {AppwriteException}
|
|
441
|
+
* @returns {URL}
|
|
442
|
+
*/
|
|
443
|
+
getFaviconURL(url: string): URL {
|
|
444
|
+
const apiPath = '/avatars/favicon';
|
|
445
|
+
const payload: Payload = {};
|
|
446
|
+
|
|
447
|
+
if (typeof url !== 'undefined') {
|
|
448
|
+
payload['url'] = url;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
const uri = new URL(this.client.config.endpoint + apiPath);
|
|
452
|
+
|
|
453
|
+
return uri;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* You can use this endpoint to show different country flags icons to your
|
|
458
|
+
* users. The code argument receives the 2 letter country code. Use width,
|
|
459
|
+
* height and quality arguments to change the output settings. Country codes
|
|
460
|
+
* follow the [ISO 3166-1](https://en.wikipedia.org/wiki/ISO_3166-1) standard.
|
|
461
|
+
*
|
|
462
|
+
* When one dimension is specified and the other is 0, the image is scaled
|
|
463
|
+
* with preserved aspect ratio. If both dimensions are 0, the API provides an
|
|
464
|
+
* image at source quality. If dimensions are not specified, the default size
|
|
465
|
+
* of image returned is 100x100px.
|
|
466
|
+
*
|
|
467
|
+
*
|
|
468
|
+
* @param {Flag} code
|
|
469
|
+
* @param {number} width
|
|
470
|
+
* @param {number} height
|
|
471
|
+
* @param {number} quality
|
|
472
|
+
* @throws {AppwriteException}
|
|
473
|
+
* @returns {URL}
|
|
474
|
+
*/
|
|
475
|
+
getFlagURL(code: Flag, width?: number, height?: number, quality?: number): URL {
|
|
476
|
+
const apiPath = '/avatars/flags/{code}'.replace('{code}', code);
|
|
477
|
+
const payload: Payload = {};
|
|
478
|
+
|
|
479
|
+
if (typeof width !== 'undefined') {
|
|
480
|
+
payload['width'] = width;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
if (typeof height !== 'undefined') {
|
|
484
|
+
payload['height'] = height;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
if (typeof quality !== 'undefined') {
|
|
488
|
+
payload['quality'] = quality;
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
const uri = new URL(this.client.config.endpoint + apiPath);
|
|
492
|
+
|
|
493
|
+
return uri;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
/**
|
|
497
|
+
* Use this endpoint to fetch a remote image URL and crop it to any image size
|
|
498
|
+
* you want. This endpoint is very useful if you need to crop and display
|
|
499
|
+
* remote images in your app or in case you want to make sure a 3rd party
|
|
500
|
+
* image is properly served using a TLS protocol.
|
|
501
|
+
*
|
|
502
|
+
* When one dimension is specified and the other is 0, the image is scaled
|
|
503
|
+
* with preserved aspect ratio. If both dimensions are 0, the API provides an
|
|
504
|
+
* image at source quality. If dimensions are not specified, the default size
|
|
505
|
+
* of image returned is 400x400px.
|
|
506
|
+
*
|
|
507
|
+
* This endpoint does not follow HTTP redirects.
|
|
508
|
+
*
|
|
509
|
+
* @param {string} url
|
|
510
|
+
* @param {number} width
|
|
511
|
+
* @param {number} height
|
|
512
|
+
* @throws {AppwriteException}
|
|
513
|
+
* @returns {URL}
|
|
514
|
+
*/
|
|
515
|
+
getImageURL(url: string, width?: number, height?: number): URL {
|
|
516
|
+
const apiPath = '/avatars/image';
|
|
517
|
+
const payload: Payload = {};
|
|
518
|
+
|
|
519
|
+
if (typeof url !== 'undefined') {
|
|
520
|
+
payload['url'] = url;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
if (typeof width !== 'undefined') {
|
|
524
|
+
payload['width'] = width;
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
if (typeof height !== 'undefined') {
|
|
528
|
+
payload['height'] = height;
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
const uri = new URL(this.client.config.endpoint + apiPath);
|
|
532
|
+
|
|
533
|
+
return uri;
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
/**
|
|
537
|
+
* Use this endpoint to show your user initials avatar icon on your website or
|
|
538
|
+
* app. By default, this route will try to print your logged-in user name or
|
|
539
|
+
* email initials. You can also overwrite the user name if you pass the 'name'
|
|
540
|
+
* parameter. If no name is given and no user is logged, an empty avatar will
|
|
541
|
+
* be returned.
|
|
542
|
+
*
|
|
543
|
+
* You can use the color and background params to change the avatar colors. By
|
|
544
|
+
* default, a random theme will be selected. The random theme will persist for
|
|
545
|
+
* the user's initials when reloading the same theme will always return for
|
|
546
|
+
* the same initials.
|
|
547
|
+
*
|
|
548
|
+
* When one dimension is specified and the other is 0, the image is scaled
|
|
549
|
+
* with preserved aspect ratio. If both dimensions are 0, the API provides an
|
|
550
|
+
* image at source quality. If dimensions are not specified, the default size
|
|
551
|
+
* of image returned is 100x100px.
|
|
552
|
+
*
|
|
553
|
+
*
|
|
554
|
+
* @param {string} name
|
|
555
|
+
* @param {number} width
|
|
556
|
+
* @param {number} height
|
|
557
|
+
* @param {string} background
|
|
558
|
+
* @throws {AppwriteException}
|
|
559
|
+
* @returns {URL}
|
|
560
|
+
*/
|
|
561
|
+
getInitialsURL(name?: string, width?: number, height?: number, background?: string): URL {
|
|
562
|
+
const apiPath = '/avatars/initials';
|
|
563
|
+
const payload: Payload = {};
|
|
564
|
+
|
|
565
|
+
if (typeof name !== 'undefined') {
|
|
566
|
+
payload['name'] = name;
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
if (typeof width !== 'undefined') {
|
|
570
|
+
payload['width'] = width;
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
if (typeof height !== 'undefined') {
|
|
574
|
+
payload['height'] = height;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
if (typeof background !== 'undefined') {
|
|
578
|
+
payload['background'] = background;
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
const uri = new URL(this.client.config.endpoint + apiPath);
|
|
582
|
+
|
|
583
|
+
return uri;
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
/**
|
|
587
|
+
* Converts a given plain text to a QR code image. You can use the query
|
|
588
|
+
* parameters to change the size and style of the resulting image.
|
|
589
|
+
*
|
|
590
|
+
*
|
|
591
|
+
* @param {string} text
|
|
592
|
+
* @param {number} size
|
|
593
|
+
* @param {number} margin
|
|
594
|
+
* @param {boolean} download
|
|
595
|
+
* @throws {AppwriteException}
|
|
596
|
+
* @returns {URL}
|
|
597
|
+
*/
|
|
598
|
+
getQRURL(text: string, size?: number, margin?: number, download?: boolean): URL {
|
|
599
|
+
const apiPath = '/avatars/qr';
|
|
600
|
+
const payload: Payload = {};
|
|
601
|
+
|
|
602
|
+
if (typeof text !== 'undefined') {
|
|
603
|
+
payload['text'] = text;
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
if (typeof size !== 'undefined') {
|
|
607
|
+
payload['size'] = size;
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
if (typeof margin !== 'undefined') {
|
|
611
|
+
payload['margin'] = margin;
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
if (typeof download !== 'undefined') {
|
|
615
|
+
payload['download'] = download;
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
const uri = new URL(this.client.config.endpoint + apiPath);
|
|
619
|
+
|
|
344
620
|
return uri;
|
|
345
621
|
}
|
|
346
622
|
};
|
package/src/services/storage.ts
CHANGED
|
@@ -260,9 +260,9 @@ export class Storage extends Service {
|
|
|
260
260
|
* @param {string} fileId
|
|
261
261
|
* @param {string} token
|
|
262
262
|
* @throws {AppwriteException}
|
|
263
|
-
* @returns {
|
|
263
|
+
* @returns {ArrayBuffer}
|
|
264
264
|
*/
|
|
265
|
-
getFileDownload(bucketId: string, fileId: string, token?: string):
|
|
265
|
+
getFileDownload(bucketId: string, fileId: string, token?: string): Promise<ArrayBuffer> {
|
|
266
266
|
if (typeof bucketId === 'undefined') {
|
|
267
267
|
throw new AppwriteException('Missing required parameter: "bucketId"');
|
|
268
268
|
}
|
|
@@ -285,7 +285,8 @@ export class Storage extends Service {
|
|
|
285
285
|
for (const [key, value] of Object.entries(Service.flatten(payload))) {
|
|
286
286
|
uri.searchParams.append(key, value);
|
|
287
287
|
}
|
|
288
|
-
return uri
|
|
288
|
+
return this.client.call('get', uri, {
|
|
289
|
+
}, payload, 'arrayBuffer');
|
|
289
290
|
}
|
|
290
291
|
|
|
291
292
|
/**
|
|
@@ -310,9 +311,9 @@ export class Storage extends Service {
|
|
|
310
311
|
* @param {ImageFormat} output
|
|
311
312
|
* @param {string} token
|
|
312
313
|
* @throws {AppwriteException}
|
|
313
|
-
* @returns {
|
|
314
|
+
* @returns {ArrayBuffer}
|
|
314
315
|
*/
|
|
315
|
-
getFilePreview(bucketId: string, fileId: string, width?: number, height?: number, gravity?: ImageGravity, quality?: number, borderWidth?: number, borderColor?: string, borderRadius?: number, opacity?: number, rotation?: number, background?: string, output?: ImageFormat, token?: string):
|
|
316
|
+
getFilePreview(bucketId: string, fileId: string, width?: number, height?: number, gravity?: ImageGravity, quality?: number, borderWidth?: number, borderColor?: string, borderRadius?: number, opacity?: number, rotation?: number, background?: string, output?: ImageFormat, token?: string): Promise<ArrayBuffer> {
|
|
316
317
|
if (typeof bucketId === 'undefined') {
|
|
317
318
|
throw new AppwriteException('Missing required parameter: "bucketId"');
|
|
318
319
|
}
|
|
@@ -379,7 +380,8 @@ export class Storage extends Service {
|
|
|
379
380
|
for (const [key, value] of Object.entries(Service.flatten(payload))) {
|
|
380
381
|
uri.searchParams.append(key, value);
|
|
381
382
|
}
|
|
382
|
-
return uri
|
|
383
|
+
return this.client.call('get', uri, {
|
|
384
|
+
}, payload, 'arrayBuffer');
|
|
383
385
|
}
|
|
384
386
|
|
|
385
387
|
/**
|
|
@@ -391,9 +393,9 @@ export class Storage extends Service {
|
|
|
391
393
|
* @param {string} fileId
|
|
392
394
|
* @param {string} token
|
|
393
395
|
* @throws {AppwriteException}
|
|
394
|
-
* @returns {
|
|
396
|
+
* @returns {ArrayBuffer}
|
|
395
397
|
*/
|
|
396
|
-
getFileView(bucketId: string, fileId: string, token?: string):
|
|
398
|
+
getFileView(bucketId: string, fileId: string, token?: string): Promise<ArrayBuffer> {
|
|
397
399
|
if (typeof bucketId === 'undefined') {
|
|
398
400
|
throw new AppwriteException('Missing required parameter: "bucketId"');
|
|
399
401
|
}
|
|
@@ -416,6 +418,136 @@ export class Storage extends Service {
|
|
|
416
418
|
for (const [key, value] of Object.entries(Service.flatten(payload))) {
|
|
417
419
|
uri.searchParams.append(key, value);
|
|
418
420
|
}
|
|
421
|
+
return this.client.call('get', uri, {
|
|
422
|
+
}, payload, 'arrayBuffer');
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* Get a file content by its unique ID. The endpoint response return with a
|
|
427
|
+
* 'Content-Disposition: attachment' header that tells the browser to start
|
|
428
|
+
* downloading the file to user downloads directory.
|
|
429
|
+
*
|
|
430
|
+
* @param {string} bucketId
|
|
431
|
+
* @param {string} fileId
|
|
432
|
+
* @param {string} token
|
|
433
|
+
* @throws {AppwriteException}
|
|
434
|
+
* @returns {URL}
|
|
435
|
+
*/
|
|
436
|
+
getFileDownloadURL(bucketId: string, fileId: string, token?: string): URL {
|
|
437
|
+
const apiPath = '/storage/buckets/{bucketId}/files/{fileId}/download'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
|
|
438
|
+
const payload: Payload = {};
|
|
439
|
+
|
|
440
|
+
if (typeof token !== 'undefined') {
|
|
441
|
+
payload['token'] = token;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
const uri = new URL(this.client.config.endpoint + apiPath);
|
|
445
|
+
|
|
446
|
+
return uri;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* Get a file preview image. Currently, this method supports preview for image
|
|
451
|
+
* files (jpg, png, and gif), other supported formats, like pdf, docs, slides,
|
|
452
|
+
* and spreadsheets, will return the file icon image. You can also pass query
|
|
453
|
+
* string arguments for cutting and resizing your preview image. Preview is
|
|
454
|
+
* supported only for image files smaller than 10MB.
|
|
455
|
+
*
|
|
456
|
+
* @param {string} bucketId
|
|
457
|
+
* @param {string} fileId
|
|
458
|
+
* @param {number} width
|
|
459
|
+
* @param {number} height
|
|
460
|
+
* @param {ImageGravity} gravity
|
|
461
|
+
* @param {number} quality
|
|
462
|
+
* @param {number} borderWidth
|
|
463
|
+
* @param {string} borderColor
|
|
464
|
+
* @param {number} borderRadius
|
|
465
|
+
* @param {number} opacity
|
|
466
|
+
* @param {number} rotation
|
|
467
|
+
* @param {string} background
|
|
468
|
+
* @param {ImageFormat} output
|
|
469
|
+
* @param {string} token
|
|
470
|
+
* @throws {AppwriteException}
|
|
471
|
+
* @returns {URL}
|
|
472
|
+
*/
|
|
473
|
+
getFilePreviewURL(bucketId: string, fileId: string, width?: number, height?: number, gravity?: ImageGravity, quality?: number, borderWidth?: number, borderColor?: string, borderRadius?: number, opacity?: number, rotation?: number, background?: string, output?: ImageFormat, token?: string): URL {
|
|
474
|
+
const apiPath = '/storage/buckets/{bucketId}/files/{fileId}/preview'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
|
|
475
|
+
const payload: Payload = {};
|
|
476
|
+
|
|
477
|
+
if (typeof width !== 'undefined') {
|
|
478
|
+
payload['width'] = width;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
if (typeof height !== 'undefined') {
|
|
482
|
+
payload['height'] = height;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
if (typeof gravity !== 'undefined') {
|
|
486
|
+
payload['gravity'] = gravity;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
if (typeof quality !== 'undefined') {
|
|
490
|
+
payload['quality'] = quality;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
if (typeof borderWidth !== 'undefined') {
|
|
494
|
+
payload['borderWidth'] = borderWidth;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
if (typeof borderColor !== 'undefined') {
|
|
498
|
+
payload['borderColor'] = borderColor;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
if (typeof borderRadius !== 'undefined') {
|
|
502
|
+
payload['borderRadius'] = borderRadius;
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
if (typeof opacity !== 'undefined') {
|
|
506
|
+
payload['opacity'] = opacity;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
if (typeof rotation !== 'undefined') {
|
|
510
|
+
payload['rotation'] = rotation;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
if (typeof background !== 'undefined') {
|
|
514
|
+
payload['background'] = background;
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
if (typeof output !== 'undefined') {
|
|
518
|
+
payload['output'] = output;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
if (typeof token !== 'undefined') {
|
|
522
|
+
payload['token'] = token;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
const uri = new URL(this.client.config.endpoint + apiPath);
|
|
526
|
+
|
|
527
|
+
return uri;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
/**
|
|
531
|
+
* Get a file content by its unique ID. This endpoint is similar to the
|
|
532
|
+
* download method but returns with no 'Content-Disposition: attachment'
|
|
533
|
+
* header.
|
|
534
|
+
*
|
|
535
|
+
* @param {string} bucketId
|
|
536
|
+
* @param {string} fileId
|
|
537
|
+
* @param {string} token
|
|
538
|
+
* @throws {AppwriteException}
|
|
539
|
+
* @returns {URL}
|
|
540
|
+
*/
|
|
541
|
+
getFileViewURL(bucketId: string, fileId: string, token?: string): URL {
|
|
542
|
+
const apiPath = '/storage/buckets/{bucketId}/files/{fileId}/view'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
|
|
543
|
+
const payload: Payload = {};
|
|
544
|
+
|
|
545
|
+
if (typeof token !== 'undefined') {
|
|
546
|
+
payload['token'] = token;
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
const uri = new URL(this.client.config.endpoint + apiPath);
|
|
550
|
+
|
|
419
551
|
return uri;
|
|
420
552
|
}
|
|
421
553
|
};
|
package/types/client.d.ts
CHANGED
|
@@ -138,7 +138,7 @@ declare class Client {
|
|
|
138
138
|
* @returns {() => void} Unsubscribes from events.
|
|
139
139
|
*/
|
|
140
140
|
subscribe<T extends unknown>(channels: string | string[], callback: (payload: RealtimeResponseEvent<T>) => void): () => void;
|
|
141
|
-
call(method: string, url: URL, headers?: Headers, params?: Payload): Promise<any>;
|
|
141
|
+
call(method: string, url: URL, headers?: Headers, params?: Payload, responseType?: string): Promise<any>;
|
|
142
142
|
}
|
|
143
143
|
export { Client, AppwriteException };
|
|
144
144
|
export type { Models, Payload };
|