node-appwrite 12.0.0 → 12.1.0-rc.4
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/.travis.yml +18 -8
- package/dist/client.d.mts +131 -0
- package/dist/client.d.ts +131 -0
- package/dist/client.js +302 -0
- package/dist/client.js.map +1 -0
- package/dist/client.mjs +295 -0
- package/dist/client.mjs.map +1 -0
- package/dist/enums/authentication-factor.d.mts +8 -0
- package/dist/enums/authentication-factor.d.ts +8 -0
- package/dist/enums/authentication-factor.js +13 -0
- package/dist/enums/authentication-factor.js.map +1 -0
- package/dist/enums/authentication-factor.mjs +11 -0
- package/dist/enums/authentication-factor.mjs.map +1 -0
- package/dist/enums/authenticator-type.d.mts +5 -0
- package/dist/enums/authenticator-type.d.ts +5 -0
- package/dist/enums/authenticator-type.js +10 -0
- package/dist/enums/authenticator-type.js.map +1 -0
- package/dist/enums/authenticator-type.mjs +8 -0
- package/dist/enums/authenticator-type.mjs.map +1 -0
- package/dist/enums/browser.d.mts +18 -0
- package/dist/enums/browser.d.ts +18 -0
- package/dist/enums/browser.js +23 -0
- package/dist/enums/browser.js.map +1 -0
- package/dist/enums/browser.mjs +21 -0
- package/dist/enums/browser.mjs.map +1 -0
- package/dist/enums/compression.d.mts +7 -0
- package/dist/enums/compression.d.ts +7 -0
- package/dist/enums/compression.js +12 -0
- package/dist/enums/compression.js.map +1 -0
- package/dist/enums/compression.mjs +10 -0
- package/dist/enums/compression.mjs.map +1 -0
- package/dist/enums/credit-card.d.mts +20 -0
- package/dist/enums/credit-card.d.ts +20 -0
- package/dist/enums/credit-card.js +25 -0
- package/dist/enums/credit-card.js.map +1 -0
- package/dist/enums/credit-card.mjs +23 -0
- package/dist/enums/credit-card.mjs.map +1 -0
- package/dist/enums/execution-method.d.mts +10 -0
- package/dist/enums/execution-method.d.ts +10 -0
- package/dist/enums/execution-method.js +15 -0
- package/dist/enums/execution-method.js.map +1 -0
- package/dist/enums/execution-method.mjs +13 -0
- package/dist/enums/execution-method.mjs.map +1 -0
- package/dist/enums/flag.d.mts +198 -0
- package/dist/enums/flag.d.ts +198 -0
- package/dist/enums/flag.js +203 -0
- package/dist/enums/flag.js.map +1 -0
- package/dist/enums/flag.mjs +201 -0
- package/dist/enums/flag.mjs.map +1 -0
- package/dist/enums/image-format.d.mts +9 -0
- package/dist/enums/image-format.d.ts +9 -0
- package/dist/enums/image-format.js +14 -0
- package/dist/enums/image-format.js.map +1 -0
- package/dist/enums/image-format.mjs +12 -0
- package/dist/enums/image-format.mjs.map +1 -0
- package/dist/enums/image-gravity.d.mts +13 -0
- package/dist/enums/image-gravity.d.ts +13 -0
- package/dist/enums/image-gravity.js +18 -0
- package/dist/enums/image-gravity.js.map +1 -0
- package/dist/enums/image-gravity.mjs +16 -0
- package/dist/enums/image-gravity.mjs.map +1 -0
- package/dist/enums/index-type.d.mts +7 -0
- package/dist/enums/index-type.d.ts +7 -0
- package/dist/enums/index-type.js +12 -0
- package/dist/enums/index-type.js.map +1 -0
- package/dist/enums/index-type.mjs +10 -0
- package/dist/enums/index-type.mjs.map +1 -0
- package/dist/enums/messaging-provider-type.d.mts +7 -0
- package/dist/enums/messaging-provider-type.d.ts +7 -0
- package/dist/enums/messaging-provider-type.js +12 -0
- package/dist/enums/messaging-provider-type.js.map +1 -0
- package/dist/enums/messaging-provider-type.mjs +10 -0
- package/dist/enums/messaging-provider-type.mjs.map +1 -0
- package/dist/enums/name.d.mts +17 -0
- package/dist/enums/name.d.ts +17 -0
- package/dist/enums/name.js +22 -0
- package/dist/enums/name.js.map +1 -0
- package/dist/enums/name.mjs +20 -0
- package/dist/enums/name.mjs.map +1 -0
- package/dist/enums/o-auth-provider.d.mts +43 -0
- package/dist/enums/o-auth-provider.d.ts +43 -0
- package/dist/enums/o-auth-provider.js +48 -0
- package/dist/enums/o-auth-provider.js.map +1 -0
- package/dist/enums/o-auth-provider.mjs +46 -0
- package/dist/enums/o-auth-provider.mjs.map +1 -0
- package/dist/enums/password-hash.d.mts +15 -0
- package/dist/enums/password-hash.d.ts +15 -0
- package/dist/enums/password-hash.js +20 -0
- package/dist/enums/password-hash.js.map +1 -0
- package/dist/enums/password-hash.mjs +18 -0
- package/dist/enums/password-hash.mjs.map +1 -0
- package/dist/enums/relation-mutate.d.mts +7 -0
- package/dist/enums/relation-mutate.d.ts +7 -0
- package/dist/enums/relation-mutate.js +12 -0
- package/dist/enums/relation-mutate.js.map +1 -0
- package/dist/enums/relation-mutate.mjs +10 -0
- package/dist/enums/relation-mutate.mjs.map +1 -0
- package/dist/enums/relationship-type.d.mts +8 -0
- package/dist/enums/relationship-type.d.ts +8 -0
- package/dist/enums/relationship-type.js +13 -0
- package/dist/enums/relationship-type.js.map +1 -0
- package/dist/enums/relationship-type.mjs +11 -0
- package/dist/enums/relationship-type.mjs.map +1 -0
- package/dist/enums/runtime.d.mts +48 -0
- package/dist/enums/runtime.d.ts +48 -0
- package/dist/enums/runtime.js +53 -0
- package/dist/enums/runtime.js.map +1 -0
- package/dist/enums/runtime.mjs +51 -0
- package/dist/enums/runtime.mjs.map +1 -0
- package/dist/enums/smtp-encryption.d.mts +7 -0
- package/dist/enums/smtp-encryption.d.ts +7 -0
- package/dist/enums/smtp-encryption.js +12 -0
- package/dist/enums/smtp-encryption.js.map +1 -0
- package/dist/enums/smtp-encryption.mjs +10 -0
- package/dist/enums/smtp-encryption.mjs.map +1 -0
- package/dist/id.d.mts +7 -0
- package/dist/id.d.ts +7 -0
- package/dist/id.js +29 -0
- package/dist/id.js.map +1 -0
- package/dist/id.mjs +27 -0
- package/dist/id.mjs.map +1 -0
- package/dist/index.d.mts +35 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.js +180 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +35 -0
- package/dist/index.mjs.map +1 -0
- package/dist/inputFile.d.mts +9 -0
- package/dist/inputFile.d.ts +9 -0
- package/dist/inputFile.js +23 -0
- package/dist/inputFile.js.map +1 -0
- package/dist/inputFile.mjs +21 -0
- package/dist/inputFile.mjs.map +1 -0
- package/dist/models.d.mts +2406 -0
- package/dist/models.d.ts +2406 -0
- package/dist/models.js +4 -0
- package/dist/models.js.map +1 -0
- package/dist/models.mjs +3 -0
- package/dist/models.mjs.map +1 -0
- package/dist/permission.d.mts +9 -0
- package/dist/permission.d.ts +9 -0
- package/dist/permission.js +23 -0
- package/dist/permission.js.map +1 -0
- package/dist/permission.mjs +21 -0
- package/dist/permission.mjs.map +1 -0
- package/dist/query.d.mts +35 -0
- package/dist/query.d.ts +35 -0
- package/dist/query.js +49 -0
- package/dist/query.js.map +1 -0
- package/dist/query.mjs +47 -0
- package/dist/query.mjs.map +1 -0
- package/dist/role.d.mts +72 -0
- package/dist/role.d.ts +72 -0
- package/dist/role.js +96 -0
- package/dist/role.js.map +1 -0
- package/dist/role.mjs +94 -0
- package/dist/role.mjs.map +1 -0
- package/dist/services/account.d.mts +478 -0
- package/dist/services/account.d.ts +478 -0
- package/dist/services/account.js +1331 -0
- package/dist/services/account.js.map +1 -0
- package/dist/services/account.mjs +1329 -0
- package/dist/services/account.mjs.map +1 -0
- package/dist/services/avatars.d.mts +118 -0
- package/dist/services/avatars.d.ts +118 -0
- package/dist/services/avatars.js +297 -0
- package/dist/services/avatars.js.map +1 -0
- package/dist/services/avatars.mjs +295 -0
- package/dist/services/avatars.mjs.map +1 -0
- package/dist/services/databases.d.mts +606 -0
- package/dist/services/databases.d.ts +606 -0
- package/dist/services/databases.js +1908 -0
- package/dist/services/databases.js.map +1 -0
- package/dist/services/databases.mjs +1906 -0
- package/dist/services/databases.mjs.map +1 -0
- package/dist/services/functions.d.mts +287 -0
- package/dist/services/functions.d.ts +287 -0
- package/dist/services/functions.js +837 -0
- package/dist/services/functions.js.map +1 -0
- package/dist/services/functions.mjs +835 -0
- package/dist/services/functions.mjs.map +1 -0
- package/dist/services/graphql.d.mts +30 -0
- package/dist/services/graphql.d.ts +30 -0
- package/dist/services/graphql.js +73 -0
- package/dist/services/graphql.js.map +1 -0
- package/dist/services/graphql.mjs +71 -0
- package/dist/services/graphql.mjs.map +1 -0
- package/dist/services/health.d.mts +235 -0
- package/dist/services/health.d.ts +235 -0
- package/dist/services/health.js +584 -0
- package/dist/services/health.js.map +1 -0
- package/dist/services/health.mjs +582 -0
- package/dist/services/health.mjs.map +1 -0
- package/dist/services/locale.d.mts +84 -0
- package/dist/services/locale.d.ts +84 -0
- package/dist/services/locale.js +189 -0
- package/dist/services/locale.js.map +1 -0
- package/dist/services/locale.mjs +187 -0
- package/dist/services/locale.mjs.map +1 -0
- package/dist/services/messaging.d.mts +688 -0
- package/dist/services/messaging.d.ts +688 -0
- package/dist/services/messaging.js +2152 -0
- package/dist/services/messaging.js.map +1 -0
- package/dist/services/messaging.mjs +2150 -0
- package/dist/services/messaging.mjs.map +1 -0
- package/dist/services/storage.d.mts +193 -0
- package/dist/services/storage.d.ts +193 -0
- package/dist/services/storage.js +550 -0
- package/dist/services/storage.js.map +1 -0
- package/dist/services/storage.mjs +548 -0
- package/dist/services/storage.mjs.map +1 -0
- package/dist/services/teams.d.mts +171 -0
- package/dist/services/teams.d.ts +171 -0
- package/dist/services/teams.js +466 -0
- package/dist/services/teams.js.map +1 -0
- package/dist/services/teams.mjs +464 -0
- package/dist/services/teams.mjs.map +1 -0
- package/dist/services/users.d.mts +490 -0
- package/dist/services/users.d.ts +490 -0
- package/dist/services/users.js +1464 -0
- package/dist/services/users.js.map +1 -0
- package/dist/services/users.mjs +1462 -0
- package/dist/services/users.mjs.map +1 -0
- package/docs/examples/functions/create-deployment.md +1 -1
- package/docs/examples/storage/create-file.md +1 -1
- package/package.json +35 -5
- package/src/client.ts +366 -0
- package/src/enums/authentication-factor.ts +6 -0
- package/src/enums/authenticator-type.ts +3 -0
- package/src/enums/browser.ts +16 -0
- package/src/enums/compression.ts +5 -0
- package/src/enums/credit-card.ts +18 -0
- package/src/enums/execution-method.ts +8 -0
- package/src/enums/flag.ts +196 -0
- package/src/enums/image-format.ts +7 -0
- package/src/enums/image-gravity.ts +11 -0
- package/src/enums/index-type.ts +5 -0
- package/src/enums/messaging-provider-type.ts +5 -0
- package/src/enums/name.ts +15 -0
- package/src/enums/o-auth-provider.ts +41 -0
- package/src/enums/password-hash.ts +13 -0
- package/src/enums/relation-mutate.ts +5 -0
- package/src/enums/relationship-type.ts +6 -0
- package/src/enums/runtime.ts +46 -0
- package/src/enums/smtp-encryption.ts +5 -0
- package/src/id.ts +28 -0
- package/src/index.ts +35 -0
- package/src/inputFile.ts +23 -0
- package/src/models.ts +2404 -0
- package/src/permission.ts +22 -0
- package/src/query.ts +101 -0
- package/{lib/role.js → src/role.ts} +23 -25
- package/src/services/account.ts +1418 -0
- package/src/services/avatars.ts +312 -0
- package/{lib/services/databases.js → src/services/databases.ts} +644 -638
- package/{lib/services/functions.js → src/services/functions.ts} +317 -369
- package/{lib/services/graphql.js → src/services/graphql.ts} +35 -34
- package/src/services/health.ts +629 -0
- package/src/services/locale.ts +205 -0
- package/{lib/services/messaging.js → src/services/messaging.ts} +658 -633
- package/{lib/services/storage.js → src/services/storage.ts} +211 -298
- package/{lib/services/teams.js → src/services/teams.ts} +211 -200
- package/{lib/services/users.js → src/services/users.ts} +603 -519
- package/tsconfig.json +18 -0
- package/tsup.config.js +19 -0
- package/index.d.ts +0 -6656
- package/index.js +0 -75
- package/lib/client.js +0 -245
- package/lib/enums/authentication-factor.js +0 -8
- package/lib/enums/authenticator-type.js +0 -5
- package/lib/enums/browser.js +0 -18
- package/lib/enums/compression.js +0 -7
- package/lib/enums/credit-card.js +0 -20
- package/lib/enums/execution-method.js +0 -10
- package/lib/enums/flag.js +0 -198
- package/lib/enums/image-format.js +0 -9
- package/lib/enums/image-gravity.js +0 -13
- package/lib/enums/index-type.js +0 -7
- package/lib/enums/messaging-provider-type.js +0 -7
- package/lib/enums/name.js +0 -17
- package/lib/enums/o-auth-provider.js +0 -43
- package/lib/enums/password-hash.js +0 -15
- package/lib/enums/relation-mutate.js +0 -7
- package/lib/enums/relationship-type.js +0 -8
- package/lib/enums/runtime.js +0 -48
- package/lib/enums/smtp-encryption.js +0 -7
- package/lib/exception.js +0 -10
- package/lib/id.js +0 -12
- package/lib/inputFile.js +0 -117
- package/lib/permission.js +0 -24
- package/lib/query.js +0 -90
- package/lib/service.js +0 -10
- package/lib/services/account.js +0 -1365
- package/lib/services/avatars.js +0 -325
- package/lib/services/health.js +0 -513
- package/lib/services/locale.js +0 -169
|
@@ -1,49 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const { promisify } = require('util');
|
|
7
|
-
const fs = require('fs');
|
|
8
|
-
const { File } = require('undici');
|
|
9
|
-
const Query = require('../query.js');
|
|
1
|
+
import { AppwriteException, Client, type Payload, UploadProgress } from '../client';
|
|
2
|
+
import type { Models } from '../models';
|
|
3
|
+
import { Compression } from '../enums/compression';
|
|
4
|
+
import { ImageGravity } from '../enums/image-gravity';
|
|
5
|
+
import { ImageFormat } from '../enums/image-format';
|
|
10
6
|
|
|
11
|
-
class Storage
|
|
12
|
-
|
|
13
|
-
constructor(client)
|
|
14
|
-
{
|
|
15
|
-
super(client);
|
|
16
|
-
}
|
|
7
|
+
export class Storage {
|
|
8
|
+
client: Client;
|
|
17
9
|
|
|
10
|
+
constructor(client: Client) {
|
|
11
|
+
this.client = client;
|
|
12
|
+
}
|
|
18
13
|
|
|
19
14
|
/**
|
|
20
15
|
* List buckets
|
|
21
16
|
*
|
|
22
|
-
* Get a list of all the storage buckets. You can use the query params to
|
|
23
|
-
* filter your results.
|
|
17
|
+
* Get a list of all the storage buckets. You can use the query params to filter your results.
|
|
24
18
|
*
|
|
25
19
|
* @param {string[]} queries
|
|
26
20
|
* @param {string} search
|
|
27
21
|
* @throws {AppwriteException}
|
|
28
|
-
* @returns {Promise}
|
|
22
|
+
* @returns {Promise<Models.BucketList>}
|
|
29
23
|
*/
|
|
30
|
-
async listBuckets(queries, search) {
|
|
24
|
+
async listBuckets(queries?: string[], search?: string): Promise<Models.BucketList> {
|
|
31
25
|
const apiPath = '/storage/buckets';
|
|
32
|
-
|
|
33
|
-
|
|
26
|
+
const payload: Payload = {};
|
|
34
27
|
if (typeof queries !== 'undefined') {
|
|
35
28
|
payload['queries'] = queries;
|
|
36
29
|
}
|
|
37
|
-
|
|
38
30
|
if (typeof search !== 'undefined') {
|
|
39
31
|
payload['search'] = search;
|
|
40
32
|
}
|
|
33
|
+
const uri = new URL(this.client.config.endpoint + apiPath);
|
|
41
34
|
|
|
42
|
-
|
|
35
|
+
const apiHeaders: { [header: string]: string } = {
|
|
43
36
|
'content-type': 'application/json',
|
|
44
|
-
}
|
|
45
|
-
}
|
|
37
|
+
}
|
|
46
38
|
|
|
39
|
+
return await this.client.call(
|
|
40
|
+
'get',
|
|
41
|
+
uri,
|
|
42
|
+
apiHeaders,
|
|
43
|
+
payload,
|
|
44
|
+
);
|
|
45
|
+
}
|
|
47
46
|
/**
|
|
48
47
|
* Create bucket
|
|
49
48
|
*
|
|
@@ -60,88 +59,88 @@ class Storage extends Service {
|
|
|
60
59
|
* @param {boolean} encryption
|
|
61
60
|
* @param {boolean} antivirus
|
|
62
61
|
* @throws {AppwriteException}
|
|
63
|
-
* @returns {Promise}
|
|
62
|
+
* @returns {Promise<Models.Bucket>}
|
|
64
63
|
*/
|
|
65
|
-
async createBucket(bucketId, name, permissions, fileSecurity, enabled, maximumFileSize, allowedFileExtensions, compression, encryption, antivirus) {
|
|
66
|
-
const apiPath = '/storage/buckets';
|
|
67
|
-
let payload = {};
|
|
64
|
+
async createBucket(bucketId: string, name: string, permissions?: string[], fileSecurity?: boolean, enabled?: boolean, maximumFileSize?: number, allowedFileExtensions?: string[], compression?: Compression, encryption?: boolean, antivirus?: boolean): Promise<Models.Bucket> {
|
|
68
65
|
if (typeof bucketId === 'undefined') {
|
|
69
66
|
throw new AppwriteException('Missing required parameter: "bucketId"');
|
|
70
67
|
}
|
|
71
|
-
|
|
72
68
|
if (typeof name === 'undefined') {
|
|
73
69
|
throw new AppwriteException('Missing required parameter: "name"');
|
|
74
70
|
}
|
|
75
|
-
|
|
76
|
-
|
|
71
|
+
const apiPath = '/storage/buckets';
|
|
72
|
+
const payload: Payload = {};
|
|
77
73
|
if (typeof bucketId !== 'undefined') {
|
|
78
74
|
payload['bucketId'] = bucketId;
|
|
79
75
|
}
|
|
80
|
-
|
|
81
76
|
if (typeof name !== 'undefined') {
|
|
82
77
|
payload['name'] = name;
|
|
83
78
|
}
|
|
84
|
-
|
|
85
79
|
if (typeof permissions !== 'undefined') {
|
|
86
80
|
payload['permissions'] = permissions;
|
|
87
81
|
}
|
|
88
|
-
|
|
89
82
|
if (typeof fileSecurity !== 'undefined') {
|
|
90
83
|
payload['fileSecurity'] = fileSecurity;
|
|
91
84
|
}
|
|
92
|
-
|
|
93
85
|
if (typeof enabled !== 'undefined') {
|
|
94
86
|
payload['enabled'] = enabled;
|
|
95
87
|
}
|
|
96
|
-
|
|
97
88
|
if (typeof maximumFileSize !== 'undefined') {
|
|
98
89
|
payload['maximumFileSize'] = maximumFileSize;
|
|
99
90
|
}
|
|
100
|
-
|
|
101
91
|
if (typeof allowedFileExtensions !== 'undefined') {
|
|
102
92
|
payload['allowedFileExtensions'] = allowedFileExtensions;
|
|
103
93
|
}
|
|
104
|
-
|
|
105
94
|
if (typeof compression !== 'undefined') {
|
|
106
95
|
payload['compression'] = compression;
|
|
107
96
|
}
|
|
108
|
-
|
|
109
97
|
if (typeof encryption !== 'undefined') {
|
|
110
98
|
payload['encryption'] = encryption;
|
|
111
99
|
}
|
|
112
|
-
|
|
113
100
|
if (typeof antivirus !== 'undefined') {
|
|
114
101
|
payload['antivirus'] = antivirus;
|
|
115
102
|
}
|
|
103
|
+
const uri = new URL(this.client.config.endpoint + apiPath);
|
|
116
104
|
|
|
117
|
-
|
|
105
|
+
const apiHeaders: { [header: string]: string } = {
|
|
118
106
|
'content-type': 'application/json',
|
|
119
|
-
}
|
|
120
|
-
}
|
|
107
|
+
}
|
|
121
108
|
|
|
109
|
+
return await this.client.call(
|
|
110
|
+
'post',
|
|
111
|
+
uri,
|
|
112
|
+
apiHeaders,
|
|
113
|
+
payload,
|
|
114
|
+
);
|
|
115
|
+
}
|
|
122
116
|
/**
|
|
123
117
|
* Get bucket
|
|
124
118
|
*
|
|
125
|
-
* Get a storage bucket by its unique ID. This endpoint response returns a
|
|
126
|
-
* JSON object with the storage bucket metadata.
|
|
119
|
+
* Get a storage bucket by its unique ID. This endpoint response returns a JSON object with the storage bucket metadata.
|
|
127
120
|
*
|
|
128
121
|
* @param {string} bucketId
|
|
129
122
|
* @throws {AppwriteException}
|
|
130
|
-
* @returns {Promise}
|
|
123
|
+
* @returns {Promise<Models.Bucket>}
|
|
131
124
|
*/
|
|
132
|
-
async getBucket(bucketId) {
|
|
133
|
-
const apiPath = '/storage/buckets/{bucketId}'.replace('{bucketId}', bucketId);
|
|
134
|
-
let payload = {};
|
|
125
|
+
async getBucket(bucketId: string): Promise<Models.Bucket> {
|
|
135
126
|
if (typeof bucketId === 'undefined') {
|
|
136
127
|
throw new AppwriteException('Missing required parameter: "bucketId"');
|
|
137
128
|
}
|
|
129
|
+
const apiPath = '/storage/buckets/{bucketId}'.replace('{bucketId}', bucketId);
|
|
130
|
+
const payload: Payload = {};
|
|
131
|
+
const uri = new URL(this.client.config.endpoint + apiPath);
|
|
138
132
|
|
|
139
|
-
|
|
140
|
-
return await this.client.call('get', apiPath, {
|
|
133
|
+
const apiHeaders: { [header: string]: string } = {
|
|
141
134
|
'content-type': 'application/json',
|
|
142
|
-
}
|
|
143
|
-
}
|
|
135
|
+
}
|
|
144
136
|
|
|
137
|
+
return await this.client.call(
|
|
138
|
+
'get',
|
|
139
|
+
uri,
|
|
140
|
+
apiHeaders,
|
|
141
|
+
payload,
|
|
142
|
+
);
|
|
143
|
+
}
|
|
145
144
|
/**
|
|
146
145
|
* Update bucket
|
|
147
146
|
*
|
|
@@ -158,61 +157,57 @@ class Storage extends Service {
|
|
|
158
157
|
* @param {boolean} encryption
|
|
159
158
|
* @param {boolean} antivirus
|
|
160
159
|
* @throws {AppwriteException}
|
|
161
|
-
* @returns {Promise}
|
|
160
|
+
* @returns {Promise<Models.Bucket>}
|
|
162
161
|
*/
|
|
163
|
-
async updateBucket(bucketId, name, permissions, fileSecurity, enabled, maximumFileSize, allowedFileExtensions, compression, encryption, antivirus) {
|
|
164
|
-
const apiPath = '/storage/buckets/{bucketId}'.replace('{bucketId}', bucketId);
|
|
165
|
-
let payload = {};
|
|
162
|
+
async updateBucket(bucketId: string, name: string, permissions?: string[], fileSecurity?: boolean, enabled?: boolean, maximumFileSize?: number, allowedFileExtensions?: string[], compression?: Compression, encryption?: boolean, antivirus?: boolean): Promise<Models.Bucket> {
|
|
166
163
|
if (typeof bucketId === 'undefined') {
|
|
167
164
|
throw new AppwriteException('Missing required parameter: "bucketId"');
|
|
168
165
|
}
|
|
169
|
-
|
|
170
166
|
if (typeof name === 'undefined') {
|
|
171
167
|
throw new AppwriteException('Missing required parameter: "name"');
|
|
172
168
|
}
|
|
173
|
-
|
|
174
|
-
|
|
169
|
+
const apiPath = '/storage/buckets/{bucketId}'.replace('{bucketId}', bucketId);
|
|
170
|
+
const payload: Payload = {};
|
|
175
171
|
if (typeof name !== 'undefined') {
|
|
176
172
|
payload['name'] = name;
|
|
177
173
|
}
|
|
178
|
-
|
|
179
174
|
if (typeof permissions !== 'undefined') {
|
|
180
175
|
payload['permissions'] = permissions;
|
|
181
176
|
}
|
|
182
|
-
|
|
183
177
|
if (typeof fileSecurity !== 'undefined') {
|
|
184
178
|
payload['fileSecurity'] = fileSecurity;
|
|
185
179
|
}
|
|
186
|
-
|
|
187
180
|
if (typeof enabled !== 'undefined') {
|
|
188
181
|
payload['enabled'] = enabled;
|
|
189
182
|
}
|
|
190
|
-
|
|
191
183
|
if (typeof maximumFileSize !== 'undefined') {
|
|
192
184
|
payload['maximumFileSize'] = maximumFileSize;
|
|
193
185
|
}
|
|
194
|
-
|
|
195
186
|
if (typeof allowedFileExtensions !== 'undefined') {
|
|
196
187
|
payload['allowedFileExtensions'] = allowedFileExtensions;
|
|
197
188
|
}
|
|
198
|
-
|
|
199
189
|
if (typeof compression !== 'undefined') {
|
|
200
190
|
payload['compression'] = compression;
|
|
201
191
|
}
|
|
202
|
-
|
|
203
192
|
if (typeof encryption !== 'undefined') {
|
|
204
193
|
payload['encryption'] = encryption;
|
|
205
194
|
}
|
|
206
|
-
|
|
207
195
|
if (typeof antivirus !== 'undefined') {
|
|
208
196
|
payload['antivirus'] = antivirus;
|
|
209
197
|
}
|
|
198
|
+
const uri = new URL(this.client.config.endpoint + apiPath);
|
|
210
199
|
|
|
211
|
-
|
|
200
|
+
const apiHeaders: { [header: string]: string } = {
|
|
212
201
|
'content-type': 'application/json',
|
|
213
|
-
}
|
|
214
|
-
}
|
|
202
|
+
}
|
|
215
203
|
|
|
204
|
+
return await this.client.call(
|
|
205
|
+
'put',
|
|
206
|
+
uri,
|
|
207
|
+
apiHeaders,
|
|
208
|
+
payload,
|
|
209
|
+
);
|
|
210
|
+
}
|
|
216
211
|
/**
|
|
217
212
|
* Delete bucket
|
|
218
213
|
*
|
|
@@ -220,338 +215,258 @@ class Storage extends Service {
|
|
|
220
215
|
*
|
|
221
216
|
* @param {string} bucketId
|
|
222
217
|
* @throws {AppwriteException}
|
|
223
|
-
* @returns {Promise}
|
|
218
|
+
* @returns {Promise<{}>}
|
|
224
219
|
*/
|
|
225
|
-
async deleteBucket(bucketId) {
|
|
226
|
-
const apiPath = '/storage/buckets/{bucketId}'.replace('{bucketId}', bucketId);
|
|
227
|
-
let payload = {};
|
|
220
|
+
async deleteBucket(bucketId: string): Promise<{}> {
|
|
228
221
|
if (typeof bucketId === 'undefined') {
|
|
229
222
|
throw new AppwriteException('Missing required parameter: "bucketId"');
|
|
230
223
|
}
|
|
224
|
+
const apiPath = '/storage/buckets/{bucketId}'.replace('{bucketId}', bucketId);
|
|
225
|
+
const payload: Payload = {};
|
|
226
|
+
const uri = new URL(this.client.config.endpoint + apiPath);
|
|
231
227
|
|
|
232
|
-
|
|
233
|
-
return await this.client.call('delete', apiPath, {
|
|
228
|
+
const apiHeaders: { [header: string]: string } = {
|
|
234
229
|
'content-type': 'application/json',
|
|
235
|
-
}
|
|
236
|
-
}
|
|
230
|
+
}
|
|
237
231
|
|
|
232
|
+
return await this.client.call(
|
|
233
|
+
'delete',
|
|
234
|
+
uri,
|
|
235
|
+
apiHeaders,
|
|
236
|
+
payload,
|
|
237
|
+
);
|
|
238
|
+
}
|
|
238
239
|
/**
|
|
239
240
|
* List files
|
|
240
241
|
*
|
|
241
|
-
* Get a list of all the user files. You can use the query params to filter
|
|
242
|
-
* your results.
|
|
242
|
+
* Get a list of all the user files. You can use the query params to filter your results.
|
|
243
243
|
*
|
|
244
244
|
* @param {string} bucketId
|
|
245
245
|
* @param {string[]} queries
|
|
246
246
|
* @param {string} search
|
|
247
247
|
* @throws {AppwriteException}
|
|
248
|
-
* @returns {Promise}
|
|
248
|
+
* @returns {Promise<Models.FileList>}
|
|
249
249
|
*/
|
|
250
|
-
async listFiles(bucketId, queries, search) {
|
|
251
|
-
const apiPath = '/storage/buckets/{bucketId}/files'.replace('{bucketId}', bucketId);
|
|
252
|
-
let payload = {};
|
|
250
|
+
async listFiles(bucketId: string, queries?: string[], search?: string): Promise<Models.FileList> {
|
|
253
251
|
if (typeof bucketId === 'undefined') {
|
|
254
252
|
throw new AppwriteException('Missing required parameter: "bucketId"');
|
|
255
253
|
}
|
|
256
|
-
|
|
257
|
-
|
|
254
|
+
const apiPath = '/storage/buckets/{bucketId}/files'.replace('{bucketId}', bucketId);
|
|
255
|
+
const payload: Payload = {};
|
|
258
256
|
if (typeof queries !== 'undefined') {
|
|
259
257
|
payload['queries'] = queries;
|
|
260
258
|
}
|
|
261
|
-
|
|
262
259
|
if (typeof search !== 'undefined') {
|
|
263
260
|
payload['search'] = search;
|
|
264
261
|
}
|
|
262
|
+
const uri = new URL(this.client.config.endpoint + apiPath);
|
|
265
263
|
|
|
266
|
-
|
|
264
|
+
const apiHeaders: { [header: string]: string } = {
|
|
267
265
|
'content-type': 'application/json',
|
|
268
|
-
}
|
|
269
|
-
}
|
|
266
|
+
}
|
|
270
267
|
|
|
268
|
+
return await this.client.call(
|
|
269
|
+
'get',
|
|
270
|
+
uri,
|
|
271
|
+
apiHeaders,
|
|
272
|
+
payload,
|
|
273
|
+
);
|
|
274
|
+
}
|
|
271
275
|
/**
|
|
272
276
|
* Create file
|
|
273
277
|
*
|
|
274
|
-
* Create a new file. Before using this route, you should create a new bucket
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
* The `content-range` header values should always be in bytes.
|
|
283
|
-
*
|
|
284
|
-
* When the first request is sent, the server will return the **File** object,
|
|
285
|
-
* and the subsequent part request must include the file's **id** in
|
|
286
|
-
* `x-appwrite-id` header to allow the server to know that the partial upload
|
|
287
|
-
* is for the existing file and not for a new one.
|
|
288
|
-
*
|
|
289
|
-
* If you're creating a new file using one of the Appwrite SDKs, all the
|
|
290
|
-
* chunking logic will be managed by the SDK internally.
|
|
291
|
-
*
|
|
278
|
+
* Create a new file. Before using this route, you should create a new bucket resource using either a [server integration](https://appwrite.io/docs/server/storage#storageCreateBucket) API or directly from your Appwrite console.
|
|
279
|
+
|
|
280
|
+
Larger files should be uploaded using multiple requests with the [content-range](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Range) header to send a partial request with a maximum supported chunk of `5MB`. The `content-range` header values should always be in bytes.
|
|
281
|
+
|
|
282
|
+
When the first request is sent, the server will return the **File** object, and the subsequent part request must include the file's **id** in `x-appwrite-id` header to allow the server to know that the partial upload is for the existing file and not for a new one.
|
|
283
|
+
|
|
284
|
+
If you're creating a new file using one of the Appwrite SDKs, all the chunking logic will be managed by the SDK internally.
|
|
285
|
+
|
|
292
286
|
*
|
|
293
287
|
* @param {string} bucketId
|
|
294
288
|
* @param {string} fileId
|
|
295
|
-
* @param {
|
|
289
|
+
* @param {File} file
|
|
296
290
|
* @param {string[]} permissions
|
|
297
|
-
* @param {CallableFunction} onProgress
|
|
298
291
|
* @throws {AppwriteException}
|
|
299
|
-
* @returns {Promise}
|
|
292
|
+
* @returns {Promise<Models.File>}
|
|
300
293
|
*/
|
|
301
|
-
async createFile(bucketId, fileId, file, permissions, onProgress = () => {}) {
|
|
302
|
-
const apiPath = '/storage/buckets/{bucketId}/files'.replace('{bucketId}', bucketId);
|
|
303
|
-
let payload = {};
|
|
294
|
+
async createFile(bucketId: string, fileId: string, file: File, permissions?: string[], onProgress = (progress: UploadProgress) => {}): Promise<Models.File> {
|
|
304
295
|
if (typeof bucketId === 'undefined') {
|
|
305
296
|
throw new AppwriteException('Missing required parameter: "bucketId"');
|
|
306
297
|
}
|
|
307
|
-
|
|
308
298
|
if (typeof fileId === 'undefined') {
|
|
309
299
|
throw new AppwriteException('Missing required parameter: "fileId"');
|
|
310
300
|
}
|
|
311
|
-
|
|
312
301
|
if (typeof file === 'undefined') {
|
|
313
302
|
throw new AppwriteException('Missing required parameter: "file"');
|
|
314
303
|
}
|
|
315
|
-
|
|
316
|
-
|
|
304
|
+
const apiPath = '/storage/buckets/{bucketId}/files'.replace('{bucketId}', bucketId);
|
|
305
|
+
const payload: Payload = {};
|
|
317
306
|
if (typeof fileId !== 'undefined') {
|
|
318
307
|
payload['fileId'] = fileId;
|
|
319
308
|
}
|
|
320
|
-
|
|
321
309
|
if (typeof file !== 'undefined') {
|
|
322
310
|
payload['file'] = file;
|
|
323
311
|
}
|
|
324
|
-
|
|
325
312
|
if (typeof permissions !== 'undefined') {
|
|
326
313
|
payload['permissions'] = permissions;
|
|
327
314
|
}
|
|
315
|
+
const uri = new URL(this.client.config.endpoint + apiPath);
|
|
328
316
|
|
|
329
|
-
|
|
330
|
-
const size = file.size;
|
|
331
|
-
|
|
332
|
-
const apiHeaders = {
|
|
317
|
+
const apiHeaders: { [header: string]: string } = {
|
|
333
318
|
'content-type': 'multipart/form-data',
|
|
334
|
-
};
|
|
335
|
-
|
|
336
|
-
let id = undefined;
|
|
337
|
-
let response = undefined;
|
|
338
|
-
|
|
339
|
-
let chunksUploaded = 0;
|
|
340
|
-
|
|
341
|
-
if(fileId != 'unique()') {
|
|
342
|
-
try {
|
|
343
|
-
response = await this.client.call('get', apiPath + '/' + fileId, apiHeaders);
|
|
344
|
-
chunksUploaded = response.chunksUploaded;
|
|
345
|
-
} catch(e) {
|
|
346
|
-
}
|
|
347
319
|
}
|
|
348
320
|
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
return;
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
const start = ((currentChunk - 1) * client.CHUNK_SIZE);
|
|
360
|
-
let end = start + currentPosition - 1;
|
|
361
|
-
|
|
362
|
-
if(!lastUpload || currentChunk !== 1) {
|
|
363
|
-
apiHeaders['content-range'] = 'bytes ' + start + '-' + end + '/' + size;
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
let uploadableChunkTrimmed;
|
|
367
|
-
|
|
368
|
-
if(currentPosition + 1 >= client.CHUNK_SIZE) {
|
|
369
|
-
uploadableChunkTrimmed = uploadableChunk;
|
|
370
|
-
} else {
|
|
371
|
-
uploadableChunkTrimmed = new Uint8Array(currentPosition);
|
|
372
|
-
for(let i = 0; i <= currentPosition; i++) {
|
|
373
|
-
uploadableChunkTrimmed[i] = uploadableChunk[i];
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
if (id) {
|
|
378
|
-
apiHeaders['x-appwrite-id'] = id;
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
payload['file'] = { type: 'file', file: new File([uploadableChunkTrimmed], file.filename), filename: file.filename };
|
|
382
|
-
|
|
383
|
-
response = await this.client.call('post', apiPath, apiHeaders, payload);
|
|
384
|
-
|
|
385
|
-
if (!id) {
|
|
386
|
-
id = response['$id'];
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
if (onProgress !== null) {
|
|
390
|
-
onProgress({
|
|
391
|
-
$id: response['$id'],
|
|
392
|
-
progress: Math.min((currentChunk) * client.CHUNK_SIZE, size) / size * 100,
|
|
393
|
-
sizeUploaded: end+1,
|
|
394
|
-
chunksTotal: response['chunksTotal'],
|
|
395
|
-
chunksUploaded: response['chunksUploaded']
|
|
396
|
-
});
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
uploadableChunk = new Uint8Array(client.CHUNK_SIZE);
|
|
400
|
-
currentChunk++;
|
|
401
|
-
currentPosition = 0;
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
for await (const chunk of file.stream) {
|
|
405
|
-
for(const b of chunk) {
|
|
406
|
-
uploadableChunk[currentPosition] = b;
|
|
407
|
-
|
|
408
|
-
currentPosition++;
|
|
409
|
-
if(currentPosition >= client.CHUNK_SIZE) {
|
|
410
|
-
await uploadChunk();
|
|
411
|
-
currentPosition = 0;
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
if (currentPosition > 0) { // Check if there's any remaining data for the last chunk
|
|
417
|
-
await uploadChunk(true);
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
return response;
|
|
421
|
-
|
|
321
|
+
return await this.client.chunkedUpload(
|
|
322
|
+
'post',
|
|
323
|
+
uri,
|
|
324
|
+
apiHeaders,
|
|
325
|
+
payload,
|
|
326
|
+
onProgress
|
|
327
|
+
);
|
|
422
328
|
}
|
|
423
|
-
|
|
424
329
|
/**
|
|
425
330
|
* Get file
|
|
426
331
|
*
|
|
427
|
-
* Get a file by its unique ID. This endpoint response returns a JSON object
|
|
428
|
-
* with the file metadata.
|
|
332
|
+
* Get a file by its unique ID. This endpoint response returns a JSON object with the file metadata.
|
|
429
333
|
*
|
|
430
334
|
* @param {string} bucketId
|
|
431
335
|
* @param {string} fileId
|
|
432
336
|
* @throws {AppwriteException}
|
|
433
|
-
* @returns {Promise}
|
|
337
|
+
* @returns {Promise<Models.File>}
|
|
434
338
|
*/
|
|
435
|
-
async getFile(bucketId, fileId) {
|
|
436
|
-
const apiPath = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
|
|
437
|
-
let payload = {};
|
|
339
|
+
async getFile(bucketId: string, fileId: string): Promise<Models.File> {
|
|
438
340
|
if (typeof bucketId === 'undefined') {
|
|
439
341
|
throw new AppwriteException('Missing required parameter: "bucketId"');
|
|
440
342
|
}
|
|
441
|
-
|
|
442
343
|
if (typeof fileId === 'undefined') {
|
|
443
344
|
throw new AppwriteException('Missing required parameter: "fileId"');
|
|
444
345
|
}
|
|
346
|
+
const apiPath = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
|
|
347
|
+
const payload: Payload = {};
|
|
348
|
+
const uri = new URL(this.client.config.endpoint + apiPath);
|
|
445
349
|
|
|
446
|
-
|
|
447
|
-
return await this.client.call('get', apiPath, {
|
|
350
|
+
const apiHeaders: { [header: string]: string } = {
|
|
448
351
|
'content-type': 'application/json',
|
|
449
|
-
}
|
|
450
|
-
}
|
|
352
|
+
}
|
|
451
353
|
|
|
354
|
+
return await this.client.call(
|
|
355
|
+
'get',
|
|
356
|
+
uri,
|
|
357
|
+
apiHeaders,
|
|
358
|
+
payload,
|
|
359
|
+
);
|
|
360
|
+
}
|
|
452
361
|
/**
|
|
453
362
|
* Update file
|
|
454
363
|
*
|
|
455
|
-
* Update a file by its unique ID. Only users with write permissions have
|
|
456
|
-
* access to update this resource.
|
|
364
|
+
* Update a file by its unique ID. Only users with write permissions have access to update this resource.
|
|
457
365
|
*
|
|
458
366
|
* @param {string} bucketId
|
|
459
367
|
* @param {string} fileId
|
|
460
368
|
* @param {string} name
|
|
461
369
|
* @param {string[]} permissions
|
|
462
370
|
* @throws {AppwriteException}
|
|
463
|
-
* @returns {Promise}
|
|
371
|
+
* @returns {Promise<Models.File>}
|
|
464
372
|
*/
|
|
465
|
-
async updateFile(bucketId, fileId, name, permissions) {
|
|
466
|
-
const apiPath = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
|
|
467
|
-
let payload = {};
|
|
373
|
+
async updateFile(bucketId: string, fileId: string, name?: string, permissions?: string[]): Promise<Models.File> {
|
|
468
374
|
if (typeof bucketId === 'undefined') {
|
|
469
375
|
throw new AppwriteException('Missing required parameter: "bucketId"');
|
|
470
376
|
}
|
|
471
|
-
|
|
472
377
|
if (typeof fileId === 'undefined') {
|
|
473
378
|
throw new AppwriteException('Missing required parameter: "fileId"');
|
|
474
379
|
}
|
|
475
|
-
|
|
476
|
-
|
|
380
|
+
const apiPath = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
|
|
381
|
+
const payload: Payload = {};
|
|
477
382
|
if (typeof name !== 'undefined') {
|
|
478
383
|
payload['name'] = name;
|
|
479
384
|
}
|
|
480
|
-
|
|
481
385
|
if (typeof permissions !== 'undefined') {
|
|
482
386
|
payload['permissions'] = permissions;
|
|
483
387
|
}
|
|
388
|
+
const uri = new URL(this.client.config.endpoint + apiPath);
|
|
484
389
|
|
|
485
|
-
|
|
390
|
+
const apiHeaders: { [header: string]: string } = {
|
|
486
391
|
'content-type': 'application/json',
|
|
487
|
-
}
|
|
488
|
-
}
|
|
392
|
+
}
|
|
489
393
|
|
|
394
|
+
return await this.client.call(
|
|
395
|
+
'put',
|
|
396
|
+
uri,
|
|
397
|
+
apiHeaders,
|
|
398
|
+
payload,
|
|
399
|
+
);
|
|
400
|
+
}
|
|
490
401
|
/**
|
|
491
402
|
* Delete File
|
|
492
403
|
*
|
|
493
|
-
* Delete a file by its unique ID. Only users with write permissions have
|
|
494
|
-
* access to delete this resource.
|
|
404
|
+
* Delete a file by its unique ID. Only users with write permissions have access to delete this resource.
|
|
495
405
|
*
|
|
496
406
|
* @param {string} bucketId
|
|
497
407
|
* @param {string} fileId
|
|
498
408
|
* @throws {AppwriteException}
|
|
499
|
-
* @returns {Promise}
|
|
409
|
+
* @returns {Promise<{}>}
|
|
500
410
|
*/
|
|
501
|
-
async deleteFile(bucketId, fileId) {
|
|
502
|
-
const apiPath = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
|
|
503
|
-
let payload = {};
|
|
411
|
+
async deleteFile(bucketId: string, fileId: string): Promise<{}> {
|
|
504
412
|
if (typeof bucketId === 'undefined') {
|
|
505
413
|
throw new AppwriteException('Missing required parameter: "bucketId"');
|
|
506
414
|
}
|
|
507
|
-
|
|
508
415
|
if (typeof fileId === 'undefined') {
|
|
509
416
|
throw new AppwriteException('Missing required parameter: "fileId"');
|
|
510
417
|
}
|
|
418
|
+
const apiPath = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
|
|
419
|
+
const payload: Payload = {};
|
|
420
|
+
const uri = new URL(this.client.config.endpoint + apiPath);
|
|
511
421
|
|
|
512
|
-
|
|
513
|
-
return await this.client.call('delete', apiPath, {
|
|
422
|
+
const apiHeaders: { [header: string]: string } = {
|
|
514
423
|
'content-type': 'application/json',
|
|
515
|
-
}
|
|
516
|
-
}
|
|
424
|
+
}
|
|
517
425
|
|
|
426
|
+
return await this.client.call(
|
|
427
|
+
'delete',
|
|
428
|
+
uri,
|
|
429
|
+
apiHeaders,
|
|
430
|
+
payload,
|
|
431
|
+
);
|
|
432
|
+
}
|
|
518
433
|
/**
|
|
519
434
|
* Get file for download
|
|
520
435
|
*
|
|
521
|
-
* Get a file content by its unique ID. The endpoint response return with a
|
|
522
|
-
* 'Content-Disposition: attachment' header that tells the browser to start
|
|
523
|
-
* downloading the file to user downloads directory.
|
|
436
|
+
* Get a file content by its unique ID. The endpoint response return with a 'Content-Disposition: attachment' header that tells the browser to start downloading the file to user downloads directory.
|
|
524
437
|
*
|
|
525
438
|
* @param {string} bucketId
|
|
526
439
|
* @param {string} fileId
|
|
527
440
|
* @throws {AppwriteException}
|
|
528
|
-
* @returns {Promise}
|
|
441
|
+
* @returns {Promise<ArrayBuffer>}
|
|
529
442
|
*/
|
|
530
|
-
async getFileDownload(bucketId, fileId) {
|
|
531
|
-
const apiPath = '/storage/buckets/{bucketId}/files/{fileId}/download'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
|
|
532
|
-
let payload = {};
|
|
443
|
+
async getFileDownload(bucketId: string, fileId: string): Promise<ArrayBuffer> {
|
|
533
444
|
if (typeof bucketId === 'undefined') {
|
|
534
445
|
throw new AppwriteException('Missing required parameter: "bucketId"');
|
|
535
446
|
}
|
|
536
|
-
|
|
537
447
|
if (typeof fileId === 'undefined') {
|
|
538
448
|
throw new AppwriteException('Missing required parameter: "fileId"');
|
|
539
449
|
}
|
|
450
|
+
const apiPath = '/storage/buckets/{bucketId}/files/{fileId}/download'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
|
|
451
|
+
const payload: Payload = {};
|
|
452
|
+
const uri = new URL(this.client.config.endpoint + apiPath);
|
|
540
453
|
|
|
541
|
-
|
|
542
|
-
return await this.client.call('get', apiPath, {
|
|
454
|
+
const apiHeaders: { [header: string]: string } = {
|
|
543
455
|
'content-type': 'application/json',
|
|
544
|
-
}
|
|
545
|
-
}
|
|
456
|
+
}
|
|
546
457
|
|
|
458
|
+
return await this.client.call(
|
|
459
|
+
'get',
|
|
460
|
+
uri,
|
|
461
|
+
apiHeaders,
|
|
462
|
+
payload,
|
|
463
|
+
'arrayBuffer'
|
|
464
|
+
);
|
|
465
|
+
}
|
|
547
466
|
/**
|
|
548
467
|
* Get file preview
|
|
549
468
|
*
|
|
550
|
-
* Get a file preview image. Currently, this method supports preview for image
|
|
551
|
-
* files (jpg, png, and gif), other supported formats, like pdf, docs, slides,
|
|
552
|
-
* and spreadsheets, will return the file icon image. You can also pass query
|
|
553
|
-
* string arguments for cutting and resizing your preview image. Preview is
|
|
554
|
-
* supported only for image files smaller than 10MB.
|
|
469
|
+
* Get a file preview image. Currently, this method supports preview for image files (jpg, png, and gif), other supported formats, like pdf, docs, slides, and spreadsheets, will return the file icon image. You can also pass query string arguments for cutting and resizing your preview image. Preview is supported only for image files smaller than 10MB.
|
|
555
470
|
*
|
|
556
471
|
* @param {string} bucketId
|
|
557
472
|
* @param {string} fileId
|
|
@@ -567,97 +482,95 @@ class Storage extends Service {
|
|
|
567
482
|
* @param {string} background
|
|
568
483
|
* @param {ImageFormat} output
|
|
569
484
|
* @throws {AppwriteException}
|
|
570
|
-
* @returns {Promise}
|
|
485
|
+
* @returns {Promise<ArrayBuffer>}
|
|
571
486
|
*/
|
|
572
|
-
async getFilePreview(bucketId, fileId, width, height, gravity, quality, borderWidth, borderColor, borderRadius, opacity, rotation, background, output) {
|
|
573
|
-
const apiPath = '/storage/buckets/{bucketId}/files/{fileId}/preview'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
|
|
574
|
-
let payload = {};
|
|
487
|
+
async 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): Promise<ArrayBuffer> {
|
|
575
488
|
if (typeof bucketId === 'undefined') {
|
|
576
489
|
throw new AppwriteException('Missing required parameter: "bucketId"');
|
|
577
490
|
}
|
|
578
|
-
|
|
579
491
|
if (typeof fileId === 'undefined') {
|
|
580
492
|
throw new AppwriteException('Missing required parameter: "fileId"');
|
|
581
493
|
}
|
|
582
|
-
|
|
583
|
-
|
|
494
|
+
const apiPath = '/storage/buckets/{bucketId}/files/{fileId}/preview'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
|
|
495
|
+
const payload: Payload = {};
|
|
584
496
|
if (typeof width !== 'undefined') {
|
|
585
497
|
payload['width'] = width;
|
|
586
498
|
}
|
|
587
|
-
|
|
588
499
|
if (typeof height !== 'undefined') {
|
|
589
500
|
payload['height'] = height;
|
|
590
501
|
}
|
|
591
|
-
|
|
592
502
|
if (typeof gravity !== 'undefined') {
|
|
593
503
|
payload['gravity'] = gravity;
|
|
594
504
|
}
|
|
595
|
-
|
|
596
505
|
if (typeof quality !== 'undefined') {
|
|
597
506
|
payload['quality'] = quality;
|
|
598
507
|
}
|
|
599
|
-
|
|
600
508
|
if (typeof borderWidth !== 'undefined') {
|
|
601
509
|
payload['borderWidth'] = borderWidth;
|
|
602
510
|
}
|
|
603
|
-
|
|
604
511
|
if (typeof borderColor !== 'undefined') {
|
|
605
512
|
payload['borderColor'] = borderColor;
|
|
606
513
|
}
|
|
607
|
-
|
|
608
514
|
if (typeof borderRadius !== 'undefined') {
|
|
609
515
|
payload['borderRadius'] = borderRadius;
|
|
610
516
|
}
|
|
611
|
-
|
|
612
517
|
if (typeof opacity !== 'undefined') {
|
|
613
518
|
payload['opacity'] = opacity;
|
|
614
519
|
}
|
|
615
|
-
|
|
616
520
|
if (typeof rotation !== 'undefined') {
|
|
617
521
|
payload['rotation'] = rotation;
|
|
618
522
|
}
|
|
619
|
-
|
|
620
523
|
if (typeof background !== 'undefined') {
|
|
621
524
|
payload['background'] = background;
|
|
622
525
|
}
|
|
623
|
-
|
|
624
526
|
if (typeof output !== 'undefined') {
|
|
625
527
|
payload['output'] = output;
|
|
626
528
|
}
|
|
529
|
+
const uri = new URL(this.client.config.endpoint + apiPath);
|
|
627
530
|
|
|
628
|
-
|
|
531
|
+
const apiHeaders: { [header: string]: string } = {
|
|
629
532
|
'content-type': 'application/json',
|
|
630
|
-
}
|
|
631
|
-
}
|
|
533
|
+
}
|
|
632
534
|
|
|
535
|
+
return await this.client.call(
|
|
536
|
+
'get',
|
|
537
|
+
uri,
|
|
538
|
+
apiHeaders,
|
|
539
|
+
payload,
|
|
540
|
+
'arrayBuffer'
|
|
541
|
+
);
|
|
542
|
+
}
|
|
633
543
|
/**
|
|
634
544
|
* Get file for view
|
|
635
545
|
*
|
|
636
|
-
* Get a file content by its unique ID. This endpoint is similar to the
|
|
637
|
-
* download method but returns with no 'Content-Disposition: attachment'
|
|
638
|
-
* header.
|
|
546
|
+
* Get a file content by its unique ID. This endpoint is similar to the download method but returns with no 'Content-Disposition: attachment' header.
|
|
639
547
|
*
|
|
640
548
|
* @param {string} bucketId
|
|
641
549
|
* @param {string} fileId
|
|
642
550
|
* @throws {AppwriteException}
|
|
643
|
-
* @returns {Promise}
|
|
551
|
+
* @returns {Promise<ArrayBuffer>}
|
|
644
552
|
*/
|
|
645
|
-
async getFileView(bucketId, fileId) {
|
|
646
|
-
const apiPath = '/storage/buckets/{bucketId}/files/{fileId}/view'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
|
|
647
|
-
let payload = {};
|
|
553
|
+
async getFileView(bucketId: string, fileId: string): Promise<ArrayBuffer> {
|
|
648
554
|
if (typeof bucketId === 'undefined') {
|
|
649
555
|
throw new AppwriteException('Missing required parameter: "bucketId"');
|
|
650
556
|
}
|
|
651
|
-
|
|
652
557
|
if (typeof fileId === 'undefined') {
|
|
653
558
|
throw new AppwriteException('Missing required parameter: "fileId"');
|
|
654
559
|
}
|
|
560
|
+
const apiPath = '/storage/buckets/{bucketId}/files/{fileId}/view'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
|
|
561
|
+
const payload: Payload = {};
|
|
562
|
+
const uri = new URL(this.client.config.endpoint + apiPath);
|
|
655
563
|
|
|
656
|
-
|
|
657
|
-
return await this.client.call('get', apiPath, {
|
|
564
|
+
const apiHeaders: { [header: string]: string } = {
|
|
658
565
|
'content-type': 'application/json',
|
|
659
|
-
}
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
return await this.client.call(
|
|
569
|
+
'get',
|
|
570
|
+
uri,
|
|
571
|
+
apiHeaders,
|
|
572
|
+
payload,
|
|
573
|
+
'arrayBuffer'
|
|
574
|
+
);
|
|
660
575
|
}
|
|
661
576
|
}
|
|
662
|
-
|
|
663
|
-
module.exports = Storage;
|