@appwrite.io/console 0.0.1
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/.github/workflows/publish.yml +18 -0
- package/CHANGELOG.md +1 -0
- package/LICENSE +12 -0
- package/README.md +111 -0
- package/dist/cjs/package.json +3 -0
- package/dist/esm/package.json +3 -0
- package/docs/examples/account/create-anonymous-session.md +18 -0
- package/docs/examples/account/create-email-session.md +18 -0
- package/docs/examples/account/create-j-w-t.md +18 -0
- package/docs/examples/account/create-magic-u-r-l-session.md +18 -0
- package/docs/examples/account/create-o-auth2session.md +14 -0
- package/docs/examples/account/create-phone-session.md +18 -0
- package/docs/examples/account/create-phone-verification.md +18 -0
- package/docs/examples/account/create-recovery.md +18 -0
- package/docs/examples/account/create-verification.md +18 -0
- package/docs/examples/account/create.md +18 -0
- package/docs/examples/account/delete-session.md +18 -0
- package/docs/examples/account/delete-sessions.md +18 -0
- package/docs/examples/account/get-prefs.md +18 -0
- package/docs/examples/account/get-session.md +18 -0
- package/docs/examples/account/get.md +18 -0
- package/docs/examples/account/list-logs.md +18 -0
- package/docs/examples/account/list-sessions.md +18 -0
- package/docs/examples/account/update-email.md +18 -0
- package/docs/examples/account/update-magic-u-r-l-session.md +18 -0
- package/docs/examples/account/update-name.md +18 -0
- package/docs/examples/account/update-password.md +18 -0
- package/docs/examples/account/update-phone-session.md +18 -0
- package/docs/examples/account/update-phone-verification.md +18 -0
- package/docs/examples/account/update-phone.md +18 -0
- package/docs/examples/account/update-prefs.md +18 -0
- package/docs/examples/account/update-recovery.md +18 -0
- package/docs/examples/account/update-session.md +18 -0
- package/docs/examples/account/update-status.md +18 -0
- package/docs/examples/account/update-verification.md +18 -0
- package/docs/examples/avatars/get-browser.md +14 -0
- package/docs/examples/avatars/get-credit-card.md +14 -0
- package/docs/examples/avatars/get-favicon.md +14 -0
- package/docs/examples/avatars/get-flag.md +14 -0
- package/docs/examples/avatars/get-image.md +14 -0
- package/docs/examples/avatars/get-initials.md +14 -0
- package/docs/examples/avatars/get-q-r.md +14 -0
- package/docs/examples/databases/create-boolean-attribute.md +18 -0
- package/docs/examples/databases/create-collection.md +18 -0
- package/docs/examples/databases/create-datetime-attribute.md +18 -0
- package/docs/examples/databases/create-document.md +18 -0
- package/docs/examples/databases/create-email-attribute.md +18 -0
- package/docs/examples/databases/create-enum-attribute.md +18 -0
- package/docs/examples/databases/create-float-attribute.md +18 -0
- package/docs/examples/databases/create-index.md +18 -0
- package/docs/examples/databases/create-integer-attribute.md +18 -0
- package/docs/examples/databases/create-ip-attribute.md +18 -0
- package/docs/examples/databases/create-string-attribute.md +18 -0
- package/docs/examples/databases/create-url-attribute.md +18 -0
- package/docs/examples/databases/create.md +18 -0
- package/docs/examples/databases/delete-attribute.md +18 -0
- package/docs/examples/databases/delete-collection.md +18 -0
- package/docs/examples/databases/delete-document.md +18 -0
- package/docs/examples/databases/delete-index.md +18 -0
- package/docs/examples/databases/delete.md +18 -0
- package/docs/examples/databases/get-attribute.md +18 -0
- package/docs/examples/databases/get-collection-usage.md +18 -0
- package/docs/examples/databases/get-collection.md +18 -0
- package/docs/examples/databases/get-database-usage.md +18 -0
- package/docs/examples/databases/get-document.md +18 -0
- package/docs/examples/databases/get-index.md +18 -0
- package/docs/examples/databases/get-usage.md +18 -0
- package/docs/examples/databases/get.md +18 -0
- package/docs/examples/databases/list-attributes.md +18 -0
- package/docs/examples/databases/list-collection-logs.md +18 -0
- package/docs/examples/databases/list-collections.md +18 -0
- package/docs/examples/databases/list-document-logs.md +18 -0
- package/docs/examples/databases/list-documents.md +18 -0
- package/docs/examples/databases/list-indexes.md +18 -0
- package/docs/examples/databases/list-logs.md +18 -0
- package/docs/examples/databases/list.md +18 -0
- package/docs/examples/databases/update-collection.md +18 -0
- package/docs/examples/databases/update-document.md +18 -0
- package/docs/examples/databases/update.md +18 -0
- package/docs/examples/functions/create-build.md +18 -0
- package/docs/examples/functions/create-deployment.md +18 -0
- package/docs/examples/functions/create-execution.md +18 -0
- package/docs/examples/functions/create-variable.md +18 -0
- package/docs/examples/functions/create.md +18 -0
- package/docs/examples/functions/delete-deployment.md +18 -0
- package/docs/examples/functions/delete-variable.md +18 -0
- package/docs/examples/functions/delete.md +18 -0
- package/docs/examples/functions/get-deployment.md +18 -0
- package/docs/examples/functions/get-execution.md +18 -0
- package/docs/examples/functions/get-function-usage.md +18 -0
- package/docs/examples/functions/get-usage.md +18 -0
- package/docs/examples/functions/get-variable.md +18 -0
- package/docs/examples/functions/get.md +18 -0
- package/docs/examples/functions/list-deployments.md +18 -0
- package/docs/examples/functions/list-executions.md +18 -0
- package/docs/examples/functions/list-runtimes.md +18 -0
- package/docs/examples/functions/list-variables.md +18 -0
- package/docs/examples/functions/list.md +18 -0
- package/docs/examples/functions/update-deployment.md +18 -0
- package/docs/examples/functions/update-variable.md +18 -0
- package/docs/examples/functions/update.md +18 -0
- package/docs/examples/graphql/mutation.md +18 -0
- package/docs/examples/graphql/query.md +18 -0
- package/docs/examples/health/get-antivirus.md +18 -0
- package/docs/examples/health/get-cache.md +18 -0
- package/docs/examples/health/get-d-b.md +18 -0
- package/docs/examples/health/get-queue-certificates.md +18 -0
- package/docs/examples/health/get-queue-functions.md +18 -0
- package/docs/examples/health/get-queue-logs.md +18 -0
- package/docs/examples/health/get-queue-webhooks.md +18 -0
- package/docs/examples/health/get-storage-local.md +18 -0
- package/docs/examples/health/get-time.md +18 -0
- package/docs/examples/health/get.md +18 -0
- package/docs/examples/locale/get.md +18 -0
- package/docs/examples/locale/list-continents.md +18 -0
- package/docs/examples/locale/list-countries-e-u.md +18 -0
- package/docs/examples/locale/list-countries-phones.md +18 -0
- package/docs/examples/locale/list-countries.md +18 -0
- package/docs/examples/locale/list-currencies.md +18 -0
- package/docs/examples/locale/list-languages.md +18 -0
- package/docs/examples/projects/create-domain.md +18 -0
- package/docs/examples/projects/create-key.md +18 -0
- package/docs/examples/projects/create-platform.md +18 -0
- package/docs/examples/projects/create-webhook.md +18 -0
- package/docs/examples/projects/create.md +18 -0
- package/docs/examples/projects/delete-domain.md +18 -0
- package/docs/examples/projects/delete-key.md +18 -0
- package/docs/examples/projects/delete-platform.md +18 -0
- package/docs/examples/projects/delete-webhook.md +18 -0
- package/docs/examples/projects/delete.md +18 -0
- package/docs/examples/projects/get-domain.md +18 -0
- package/docs/examples/projects/get-key.md +18 -0
- package/docs/examples/projects/get-platform.md +18 -0
- package/docs/examples/projects/get-usage.md +18 -0
- package/docs/examples/projects/get-webhook.md +18 -0
- package/docs/examples/projects/get.md +18 -0
- package/docs/examples/projects/list-domains.md +18 -0
- package/docs/examples/projects/list-keys.md +18 -0
- package/docs/examples/projects/list-platforms.md +18 -0
- package/docs/examples/projects/list-webhooks.md +18 -0
- package/docs/examples/projects/list.md +18 -0
- package/docs/examples/projects/update-auth-duration.md +18 -0
- package/docs/examples/projects/update-auth-limit.md +18 -0
- package/docs/examples/projects/update-auth-sessions-limit.md +18 -0
- package/docs/examples/projects/update-auth-status.md +18 -0
- package/docs/examples/projects/update-domain-verification.md +18 -0
- package/docs/examples/projects/update-key.md +18 -0
- package/docs/examples/projects/update-o-auth2.md +18 -0
- package/docs/examples/projects/update-platform.md +18 -0
- package/docs/examples/projects/update-service-status.md +18 -0
- package/docs/examples/projects/update-webhook-signature.md +18 -0
- package/docs/examples/projects/update-webhook.md +18 -0
- package/docs/examples/projects/update.md +18 -0
- package/docs/examples/storage/create-bucket.md +18 -0
- package/docs/examples/storage/create-file.md +18 -0
- package/docs/examples/storage/delete-bucket.md +18 -0
- package/docs/examples/storage/delete-file.md +18 -0
- package/docs/examples/storage/get-bucket-usage.md +18 -0
- package/docs/examples/storage/get-bucket.md +18 -0
- package/docs/examples/storage/get-file-download.md +14 -0
- package/docs/examples/storage/get-file-preview.md +14 -0
- package/docs/examples/storage/get-file-view.md +14 -0
- package/docs/examples/storage/get-file.md +18 -0
- package/docs/examples/storage/get-usage.md +18 -0
- package/docs/examples/storage/list-buckets.md +18 -0
- package/docs/examples/storage/list-files.md +18 -0
- package/docs/examples/storage/update-bucket.md +18 -0
- package/docs/examples/storage/update-file.md +18 -0
- package/docs/examples/teams/create-membership.md +18 -0
- package/docs/examples/teams/create.md +18 -0
- package/docs/examples/teams/delete-membership.md +18 -0
- package/docs/examples/teams/delete.md +18 -0
- package/docs/examples/teams/get-membership.md +18 -0
- package/docs/examples/teams/get.md +18 -0
- package/docs/examples/teams/list-logs.md +18 -0
- package/docs/examples/teams/list-memberships.md +18 -0
- package/docs/examples/teams/list.md +18 -0
- package/docs/examples/teams/update-membership-roles.md +18 -0
- package/docs/examples/teams/update-membership-status.md +18 -0
- package/docs/examples/teams/update.md +18 -0
- package/docs/examples/users/create-argon2user.md +18 -0
- package/docs/examples/users/create-bcrypt-user.md +18 -0
- package/docs/examples/users/create-m-d5user.md +18 -0
- package/docs/examples/users/create-p-h-pass-user.md +18 -0
- package/docs/examples/users/create-s-h-a-user.md +18 -0
- package/docs/examples/users/create-scrypt-modified-user.md +18 -0
- package/docs/examples/users/create-scrypt-user.md +18 -0
- package/docs/examples/users/create.md +18 -0
- package/docs/examples/users/delete-session.md +18 -0
- package/docs/examples/users/delete-sessions.md +18 -0
- package/docs/examples/users/delete.md +18 -0
- package/docs/examples/users/get-prefs.md +18 -0
- package/docs/examples/users/get-usage.md +18 -0
- package/docs/examples/users/get.md +18 -0
- package/docs/examples/users/list-logs.md +18 -0
- package/docs/examples/users/list-memberships.md +18 -0
- package/docs/examples/users/list-sessions.md +18 -0
- package/docs/examples/users/list.md +18 -0
- package/docs/examples/users/update-email-verification.md +18 -0
- package/docs/examples/users/update-email.md +18 -0
- package/docs/examples/users/update-name.md +18 -0
- package/docs/examples/users/update-password.md +18 -0
- package/docs/examples/users/update-phone-verification.md +18 -0
- package/docs/examples/users/update-phone.md +18 -0
- package/docs/examples/users/update-prefs.md +18 -0
- package/docs/examples/users/update-status.md +18 -0
- package/package.json +40 -0
- package/rollup.config.js +31 -0
- package/src/client.ts +472 -0
- package/src/id.ts +9 -0
- package/src/index.ts +17 -0
- package/src/models.ts +2540 -0
- package/src/permission.ts +22 -0
- package/src/query.ts +56 -0
- package/src/role.ts +34 -0
- package/src/service.ts +30 -0
- package/src/services/account.ts +1009 -0
- package/src/services/avatars.ts +351 -0
- package/src/services/databases.ts +1525 -0
- package/src/services/functions.ts +814 -0
- package/src/services/graphql.ts +68 -0
- package/src/services/health.ts +202 -0
- package/src/services/locale.ts +150 -0
- package/src/services/projects.ts +1235 -0
- package/src/services/storage.ts +691 -0
- package/src/services/teams.ts +445 -0
- package/src/services/users.ts +1020 -0
- package/tsconfig.json +24 -0
|
@@ -0,0 +1,691 @@
|
|
|
1
|
+
import { Service } from '../service';
|
|
2
|
+
import { AppwriteException, Client } from '../client';
|
|
3
|
+
import type { Models } from '../models';
|
|
4
|
+
import type { UploadProgress, Payload } from '../client';
|
|
5
|
+
|
|
6
|
+
export class Storage extends Service {
|
|
7
|
+
|
|
8
|
+
constructor(client: Client)
|
|
9
|
+
{
|
|
10
|
+
super(client);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* List buckets
|
|
15
|
+
*
|
|
16
|
+
* Get a list of all the storage buckets. You can use the query params to
|
|
17
|
+
* filter your results.
|
|
18
|
+
*
|
|
19
|
+
* @param {string[]} queries
|
|
20
|
+
* @param {string} search
|
|
21
|
+
* @throws {AppwriteException}
|
|
22
|
+
* @returns {Promise}
|
|
23
|
+
*/
|
|
24
|
+
async listBuckets(queries?: string[], search?: string): Promise<Models.BucketList> {
|
|
25
|
+
let path = '/storage/buckets';
|
|
26
|
+
let payload: Payload = {};
|
|
27
|
+
|
|
28
|
+
if (typeof queries !== 'undefined') {
|
|
29
|
+
payload['queries'] = queries;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (typeof search !== 'undefined') {
|
|
33
|
+
payload['search'] = search;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const uri = new URL(this.client.config.endpoint + path);
|
|
37
|
+
return await this.client.call('get', uri, {
|
|
38
|
+
'content-type': 'application/json',
|
|
39
|
+
}, payload);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Create bucket
|
|
44
|
+
*
|
|
45
|
+
* Create a new storage bucket.
|
|
46
|
+
*
|
|
47
|
+
* @param {string} bucketId
|
|
48
|
+
* @param {string} name
|
|
49
|
+
* @param {string[]} permissions
|
|
50
|
+
* @param {boolean} fileSecurity
|
|
51
|
+
* @param {boolean} enabled
|
|
52
|
+
* @param {number} maximumFileSize
|
|
53
|
+
* @param {string[]} allowedFileExtensions
|
|
54
|
+
* @param {string} compression
|
|
55
|
+
* @param {boolean} encryption
|
|
56
|
+
* @param {boolean} antivirus
|
|
57
|
+
* @throws {AppwriteException}
|
|
58
|
+
* @returns {Promise}
|
|
59
|
+
*/
|
|
60
|
+
async createBucket(bucketId: string, name: string, permissions?: string[], fileSecurity?: boolean, enabled?: boolean, maximumFileSize?: number, allowedFileExtensions?: string[], compression?: string, encryption?: boolean, antivirus?: boolean): Promise<Models.Bucket> {
|
|
61
|
+
if (typeof bucketId === 'undefined') {
|
|
62
|
+
throw new AppwriteException('Missing required parameter: "bucketId"');
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (typeof name === 'undefined') {
|
|
66
|
+
throw new AppwriteException('Missing required parameter: "name"');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
let path = '/storage/buckets';
|
|
70
|
+
let payload: Payload = {};
|
|
71
|
+
|
|
72
|
+
if (typeof bucketId !== 'undefined') {
|
|
73
|
+
payload['bucketId'] = bucketId;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (typeof name !== 'undefined') {
|
|
77
|
+
payload['name'] = name;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (typeof permissions !== 'undefined') {
|
|
81
|
+
payload['permissions'] = permissions;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (typeof fileSecurity !== 'undefined') {
|
|
85
|
+
payload['fileSecurity'] = fileSecurity;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (typeof enabled !== 'undefined') {
|
|
89
|
+
payload['enabled'] = enabled;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (typeof maximumFileSize !== 'undefined') {
|
|
93
|
+
payload['maximumFileSize'] = maximumFileSize;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (typeof allowedFileExtensions !== 'undefined') {
|
|
97
|
+
payload['allowedFileExtensions'] = allowedFileExtensions;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (typeof compression !== 'undefined') {
|
|
101
|
+
payload['compression'] = compression;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (typeof encryption !== 'undefined') {
|
|
105
|
+
payload['encryption'] = encryption;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (typeof antivirus !== 'undefined') {
|
|
109
|
+
payload['antivirus'] = antivirus;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const uri = new URL(this.client.config.endpoint + path);
|
|
113
|
+
return await this.client.call('post', uri, {
|
|
114
|
+
'content-type': 'application/json',
|
|
115
|
+
}, payload);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Get Bucket
|
|
120
|
+
*
|
|
121
|
+
* Get a storage bucket by its unique ID. This endpoint response returns a
|
|
122
|
+
* JSON object with the storage bucket metadata.
|
|
123
|
+
*
|
|
124
|
+
* @param {string} bucketId
|
|
125
|
+
* @throws {AppwriteException}
|
|
126
|
+
* @returns {Promise}
|
|
127
|
+
*/
|
|
128
|
+
async getBucket(bucketId: string): Promise<Models.Bucket> {
|
|
129
|
+
if (typeof bucketId === 'undefined') {
|
|
130
|
+
throw new AppwriteException('Missing required parameter: "bucketId"');
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
let path = '/storage/buckets/{bucketId}'.replace('{bucketId}', bucketId);
|
|
134
|
+
let payload: Payload = {};
|
|
135
|
+
|
|
136
|
+
const uri = new URL(this.client.config.endpoint + path);
|
|
137
|
+
return await this.client.call('get', uri, {
|
|
138
|
+
'content-type': 'application/json',
|
|
139
|
+
}, payload);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Update Bucket
|
|
144
|
+
*
|
|
145
|
+
* Update a storage bucket by its unique ID.
|
|
146
|
+
*
|
|
147
|
+
* @param {string} bucketId
|
|
148
|
+
* @param {string} name
|
|
149
|
+
* @param {string[]} permissions
|
|
150
|
+
* @param {boolean} fileSecurity
|
|
151
|
+
* @param {boolean} enabled
|
|
152
|
+
* @param {number} maximumFileSize
|
|
153
|
+
* @param {string[]} allowedFileExtensions
|
|
154
|
+
* @param {string} compression
|
|
155
|
+
* @param {boolean} encryption
|
|
156
|
+
* @param {boolean} antivirus
|
|
157
|
+
* @throws {AppwriteException}
|
|
158
|
+
* @returns {Promise}
|
|
159
|
+
*/
|
|
160
|
+
async updateBucket(bucketId: string, name: string, permissions?: string[], fileSecurity?: boolean, enabled?: boolean, maximumFileSize?: number, allowedFileExtensions?: string[], compression?: string, encryption?: boolean, antivirus?: boolean): Promise<Models.Bucket> {
|
|
161
|
+
if (typeof bucketId === 'undefined') {
|
|
162
|
+
throw new AppwriteException('Missing required parameter: "bucketId"');
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (typeof name === 'undefined') {
|
|
166
|
+
throw new AppwriteException('Missing required parameter: "name"');
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
let path = '/storage/buckets/{bucketId}'.replace('{bucketId}', bucketId);
|
|
170
|
+
let payload: Payload = {};
|
|
171
|
+
|
|
172
|
+
if (typeof name !== 'undefined') {
|
|
173
|
+
payload['name'] = name;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (typeof permissions !== 'undefined') {
|
|
177
|
+
payload['permissions'] = permissions;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (typeof fileSecurity !== 'undefined') {
|
|
181
|
+
payload['fileSecurity'] = fileSecurity;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (typeof enabled !== 'undefined') {
|
|
185
|
+
payload['enabled'] = enabled;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (typeof maximumFileSize !== 'undefined') {
|
|
189
|
+
payload['maximumFileSize'] = maximumFileSize;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (typeof allowedFileExtensions !== 'undefined') {
|
|
193
|
+
payload['allowedFileExtensions'] = allowedFileExtensions;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (typeof compression !== 'undefined') {
|
|
197
|
+
payload['compression'] = compression;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (typeof encryption !== 'undefined') {
|
|
201
|
+
payload['encryption'] = encryption;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (typeof antivirus !== 'undefined') {
|
|
205
|
+
payload['antivirus'] = antivirus;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const uri = new URL(this.client.config.endpoint + path);
|
|
209
|
+
return await this.client.call('put', uri, {
|
|
210
|
+
'content-type': 'application/json',
|
|
211
|
+
}, payload);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Delete Bucket
|
|
216
|
+
*
|
|
217
|
+
* Delete a storage bucket by its unique ID.
|
|
218
|
+
*
|
|
219
|
+
* @param {string} bucketId
|
|
220
|
+
* @throws {AppwriteException}
|
|
221
|
+
* @returns {Promise}
|
|
222
|
+
*/
|
|
223
|
+
async deleteBucket(bucketId: string): Promise<{}> {
|
|
224
|
+
if (typeof bucketId === 'undefined') {
|
|
225
|
+
throw new AppwriteException('Missing required parameter: "bucketId"');
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
let path = '/storage/buckets/{bucketId}'.replace('{bucketId}', bucketId);
|
|
229
|
+
let payload: Payload = {};
|
|
230
|
+
|
|
231
|
+
const uri = new URL(this.client.config.endpoint + path);
|
|
232
|
+
return await this.client.call('delete', uri, {
|
|
233
|
+
'content-type': 'application/json',
|
|
234
|
+
}, payload);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* List Files
|
|
239
|
+
*
|
|
240
|
+
* Get a list of all the user files. You can use the query params to filter
|
|
241
|
+
* your results.
|
|
242
|
+
*
|
|
243
|
+
* @param {string} bucketId
|
|
244
|
+
* @param {string[]} queries
|
|
245
|
+
* @param {string} search
|
|
246
|
+
* @throws {AppwriteException}
|
|
247
|
+
* @returns {Promise}
|
|
248
|
+
*/
|
|
249
|
+
async listFiles(bucketId: string, queries?: string[], search?: string): Promise<Models.FileList> {
|
|
250
|
+
if (typeof bucketId === 'undefined') {
|
|
251
|
+
throw new AppwriteException('Missing required parameter: "bucketId"');
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
let path = '/storage/buckets/{bucketId}/files'.replace('{bucketId}', bucketId);
|
|
255
|
+
let payload: Payload = {};
|
|
256
|
+
|
|
257
|
+
if (typeof queries !== 'undefined') {
|
|
258
|
+
payload['queries'] = queries;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
if (typeof search !== 'undefined') {
|
|
262
|
+
payload['search'] = search;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
const uri = new URL(this.client.config.endpoint + path);
|
|
266
|
+
return await this.client.call('get', uri, {
|
|
267
|
+
'content-type': 'application/json',
|
|
268
|
+
}, payload);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Create File
|
|
273
|
+
*
|
|
274
|
+
* Create a new file. Before using this route, you should create a new bucket
|
|
275
|
+
* resource using either a [server
|
|
276
|
+
* integration](/docs/server/storage#storageCreateBucket) API or directly from
|
|
277
|
+
* your Appwrite console.
|
|
278
|
+
*
|
|
279
|
+
* Larger files should be uploaded using multiple requests with the
|
|
280
|
+
* [content-range](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Range)
|
|
281
|
+
* header to send a partial request with a maximum supported chunk of `5MB`.
|
|
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
|
+
*
|
|
292
|
+
*
|
|
293
|
+
* @param {string} bucketId
|
|
294
|
+
* @param {string} fileId
|
|
295
|
+
* @param {File} file
|
|
296
|
+
* @param {string[]} permissions
|
|
297
|
+
* @throws {AppwriteException}
|
|
298
|
+
* @returns {Promise}
|
|
299
|
+
*/
|
|
300
|
+
async createFile(bucketId: string, fileId: string, file: File, permissions?: string[], onProgress = (progress: UploadProgress) => {}): Promise<Models.File> {
|
|
301
|
+
if (typeof bucketId === 'undefined') {
|
|
302
|
+
throw new AppwriteException('Missing required parameter: "bucketId"');
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
if (typeof fileId === 'undefined') {
|
|
306
|
+
throw new AppwriteException('Missing required parameter: "fileId"');
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
if (typeof file === 'undefined') {
|
|
310
|
+
throw new AppwriteException('Missing required parameter: "file"');
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
let path = '/storage/buckets/{bucketId}/files'.replace('{bucketId}', bucketId);
|
|
314
|
+
let payload: Payload = {};
|
|
315
|
+
|
|
316
|
+
if (typeof fileId !== 'undefined') {
|
|
317
|
+
payload['fileId'] = fileId;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
if (typeof file !== 'undefined') {
|
|
321
|
+
payload['file'] = file;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
if (typeof permissions !== 'undefined') {
|
|
325
|
+
payload['permissions'] = permissions;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
const uri = new URL(this.client.config.endpoint + path);
|
|
329
|
+
|
|
330
|
+
if(!(file instanceof File)) {
|
|
331
|
+
throw new AppwriteException('Parameter "file" has to be a File.');
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
const size = file.size;
|
|
335
|
+
|
|
336
|
+
if (size <= Service.CHUNK_SIZE) {
|
|
337
|
+
return await this.client.call('post', uri, {
|
|
338
|
+
|
|
339
|
+
'content-type': 'multipart/form-data',
|
|
340
|
+
}, payload);
|
|
341
|
+
}
|
|
342
|
+
let id = undefined;
|
|
343
|
+
let response = undefined;
|
|
344
|
+
|
|
345
|
+
const headers: { [header: string]: string } = {
|
|
346
|
+
'content-type': 'multipart/form-data',
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
let counter = 0;
|
|
350
|
+
const totalCounters = Math.ceil(size / Service.CHUNK_SIZE);
|
|
351
|
+
if(fileId != 'unique()') {
|
|
352
|
+
try {
|
|
353
|
+
response = await this.client.call('GET', new URL(this.client.config.endpoint + path + '/' + fileId), headers);
|
|
354
|
+
counter = response.chunksUploaded;
|
|
355
|
+
} catch(e) {
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
for (counter; counter < totalCounters; counter++) {
|
|
360
|
+
const start = (counter * Service.CHUNK_SIZE);
|
|
361
|
+
const end = Math.min((((counter * Service.CHUNK_SIZE) + Service.CHUNK_SIZE) - 1), size);
|
|
362
|
+
|
|
363
|
+
headers['content-range'] = 'bytes ' + start + '-' + end + '/' + size
|
|
364
|
+
|
|
365
|
+
if (id) {
|
|
366
|
+
headers['x-appwrite-id'] = id;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
const stream = file.slice(start, end + 1);
|
|
370
|
+
payload['file'] = new File([stream], file.name);
|
|
371
|
+
|
|
372
|
+
response = await this.client.call('post', uri, headers, payload);
|
|
373
|
+
|
|
374
|
+
if (!id) {
|
|
375
|
+
id = response['$id'];
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
if (onProgress) {
|
|
379
|
+
onProgress({
|
|
380
|
+
$id: response.$id,
|
|
381
|
+
progress: Math.min((counter + 1) * Service.CHUNK_SIZE - 1, size) / size * 100,
|
|
382
|
+
sizeUploaded: end,
|
|
383
|
+
chunksTotal: response.chunksTotal,
|
|
384
|
+
chunksUploaded: response.chunksUploaded
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
return response;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* Get File
|
|
394
|
+
*
|
|
395
|
+
* Get a file by its unique ID. This endpoint response returns a JSON object
|
|
396
|
+
* with the file metadata.
|
|
397
|
+
*
|
|
398
|
+
* @param {string} bucketId
|
|
399
|
+
* @param {string} fileId
|
|
400
|
+
* @throws {AppwriteException}
|
|
401
|
+
* @returns {Promise}
|
|
402
|
+
*/
|
|
403
|
+
async getFile(bucketId: string, fileId: string): Promise<Models.File> {
|
|
404
|
+
if (typeof bucketId === 'undefined') {
|
|
405
|
+
throw new AppwriteException('Missing required parameter: "bucketId"');
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
if (typeof fileId === 'undefined') {
|
|
409
|
+
throw new AppwriteException('Missing required parameter: "fileId"');
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
let path = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
|
|
413
|
+
let payload: Payload = {};
|
|
414
|
+
|
|
415
|
+
const uri = new URL(this.client.config.endpoint + path);
|
|
416
|
+
return await this.client.call('get', uri, {
|
|
417
|
+
'content-type': 'application/json',
|
|
418
|
+
}, payload);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* Update File
|
|
423
|
+
*
|
|
424
|
+
* Update a file by its unique ID. Only users with write permissions have
|
|
425
|
+
* access to update this resource.
|
|
426
|
+
*
|
|
427
|
+
* @param {string} bucketId
|
|
428
|
+
* @param {string} fileId
|
|
429
|
+
* @param {string[]} permissions
|
|
430
|
+
* @throws {AppwriteException}
|
|
431
|
+
* @returns {Promise}
|
|
432
|
+
*/
|
|
433
|
+
async updateFile(bucketId: string, fileId: string, permissions?: string[]): Promise<Models.File> {
|
|
434
|
+
if (typeof bucketId === 'undefined') {
|
|
435
|
+
throw new AppwriteException('Missing required parameter: "bucketId"');
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
if (typeof fileId === 'undefined') {
|
|
439
|
+
throw new AppwriteException('Missing required parameter: "fileId"');
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
let path = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
|
|
443
|
+
let payload: Payload = {};
|
|
444
|
+
|
|
445
|
+
if (typeof permissions !== 'undefined') {
|
|
446
|
+
payload['permissions'] = permissions;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
const uri = new URL(this.client.config.endpoint + path);
|
|
450
|
+
return await this.client.call('put', uri, {
|
|
451
|
+
'content-type': 'application/json',
|
|
452
|
+
}, payload);
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
/**
|
|
456
|
+
* Delete File
|
|
457
|
+
*
|
|
458
|
+
* Delete a file by its unique ID. Only users with write permissions have
|
|
459
|
+
* access to delete this resource.
|
|
460
|
+
*
|
|
461
|
+
* @param {string} bucketId
|
|
462
|
+
* @param {string} fileId
|
|
463
|
+
* @throws {AppwriteException}
|
|
464
|
+
* @returns {Promise}
|
|
465
|
+
*/
|
|
466
|
+
async deleteFile(bucketId: string, fileId: string): Promise<{}> {
|
|
467
|
+
if (typeof bucketId === 'undefined') {
|
|
468
|
+
throw new AppwriteException('Missing required parameter: "bucketId"');
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
if (typeof fileId === 'undefined') {
|
|
472
|
+
throw new AppwriteException('Missing required parameter: "fileId"');
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
let path = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
|
|
476
|
+
let payload: Payload = {};
|
|
477
|
+
|
|
478
|
+
const uri = new URL(this.client.config.endpoint + path);
|
|
479
|
+
return await this.client.call('delete', uri, {
|
|
480
|
+
'content-type': 'application/json',
|
|
481
|
+
}, payload);
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
/**
|
|
485
|
+
* Get File for Download
|
|
486
|
+
*
|
|
487
|
+
* Get a file content by its unique ID. The endpoint response return with a
|
|
488
|
+
* 'Content-Disposition: attachment' header that tells the browser to start
|
|
489
|
+
* downloading the file to user downloads directory.
|
|
490
|
+
*
|
|
491
|
+
* @param {string} bucketId
|
|
492
|
+
* @param {string} fileId
|
|
493
|
+
* @throws {AppwriteException}
|
|
494
|
+
* @returns {URL}
|
|
495
|
+
*/
|
|
496
|
+
getFileDownload(bucketId: string, fileId: string): URL {
|
|
497
|
+
if (typeof bucketId === 'undefined') {
|
|
498
|
+
throw new AppwriteException('Missing required parameter: "bucketId"');
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
if (typeof fileId === 'undefined') {
|
|
502
|
+
throw new AppwriteException('Missing required parameter: "fileId"');
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
let path = '/storage/buckets/{bucketId}/files/{fileId}/download'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
|
|
506
|
+
let payload: Payload = {};
|
|
507
|
+
|
|
508
|
+
const uri = new URL(this.client.config.endpoint + path);
|
|
509
|
+
payload['project'] = this.client.config.project;
|
|
510
|
+
|
|
511
|
+
|
|
512
|
+
for (const [key, value] of Object.entries(Service.flatten(payload))) {
|
|
513
|
+
uri.searchParams.append(key, value);
|
|
514
|
+
}
|
|
515
|
+
return uri;
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
/**
|
|
519
|
+
* Get File Preview
|
|
520
|
+
*
|
|
521
|
+
* Get a file preview image. Currently, this method supports preview for image
|
|
522
|
+
* files (jpg, png, and gif), other supported formats, like pdf, docs, slides,
|
|
523
|
+
* and spreadsheets, will return the file icon image. You can also pass query
|
|
524
|
+
* string arguments for cutting and resizing your preview image. Preview is
|
|
525
|
+
* supported only for image files smaller than 10MB.
|
|
526
|
+
*
|
|
527
|
+
* @param {string} bucketId
|
|
528
|
+
* @param {string} fileId
|
|
529
|
+
* @param {number} width
|
|
530
|
+
* @param {number} height
|
|
531
|
+
* @param {string} gravity
|
|
532
|
+
* @param {number} quality
|
|
533
|
+
* @param {number} borderWidth
|
|
534
|
+
* @param {string} borderColor
|
|
535
|
+
* @param {number} borderRadius
|
|
536
|
+
* @param {number} opacity
|
|
537
|
+
* @param {number} rotation
|
|
538
|
+
* @param {string} background
|
|
539
|
+
* @param {string} output
|
|
540
|
+
* @throws {AppwriteException}
|
|
541
|
+
* @returns {URL}
|
|
542
|
+
*/
|
|
543
|
+
getFilePreview(bucketId: string, fileId: string, width?: number, height?: number, gravity?: string, quality?: number, borderWidth?: number, borderColor?: string, borderRadius?: number, opacity?: number, rotation?: number, background?: string, output?: string): URL {
|
|
544
|
+
if (typeof bucketId === 'undefined') {
|
|
545
|
+
throw new AppwriteException('Missing required parameter: "bucketId"');
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
if (typeof fileId === 'undefined') {
|
|
549
|
+
throw new AppwriteException('Missing required parameter: "fileId"');
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
let path = '/storage/buckets/{bucketId}/files/{fileId}/preview'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
|
|
553
|
+
let payload: Payload = {};
|
|
554
|
+
|
|
555
|
+
if (typeof width !== 'undefined') {
|
|
556
|
+
payload['width'] = width;
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
if (typeof height !== 'undefined') {
|
|
560
|
+
payload['height'] = height;
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
if (typeof gravity !== 'undefined') {
|
|
564
|
+
payload['gravity'] = gravity;
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
if (typeof quality !== 'undefined') {
|
|
568
|
+
payload['quality'] = quality;
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
if (typeof borderWidth !== 'undefined') {
|
|
572
|
+
payload['borderWidth'] = borderWidth;
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
if (typeof borderColor !== 'undefined') {
|
|
576
|
+
payload['borderColor'] = borderColor;
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
if (typeof borderRadius !== 'undefined') {
|
|
580
|
+
payload['borderRadius'] = borderRadius;
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
if (typeof opacity !== 'undefined') {
|
|
584
|
+
payload['opacity'] = opacity;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
if (typeof rotation !== 'undefined') {
|
|
588
|
+
payload['rotation'] = rotation;
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
if (typeof background !== 'undefined') {
|
|
592
|
+
payload['background'] = background;
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
if (typeof output !== 'undefined') {
|
|
596
|
+
payload['output'] = output;
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
const uri = new URL(this.client.config.endpoint + path);
|
|
600
|
+
payload['project'] = this.client.config.project;
|
|
601
|
+
|
|
602
|
+
|
|
603
|
+
for (const [key, value] of Object.entries(Service.flatten(payload))) {
|
|
604
|
+
uri.searchParams.append(key, value);
|
|
605
|
+
}
|
|
606
|
+
return uri;
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
/**
|
|
610
|
+
* Get File for View
|
|
611
|
+
*
|
|
612
|
+
* Get a file content by its unique ID. This endpoint is similar to the
|
|
613
|
+
* download method but returns with no 'Content-Disposition: attachment'
|
|
614
|
+
* header.
|
|
615
|
+
*
|
|
616
|
+
* @param {string} bucketId
|
|
617
|
+
* @param {string} fileId
|
|
618
|
+
* @throws {AppwriteException}
|
|
619
|
+
* @returns {URL}
|
|
620
|
+
*/
|
|
621
|
+
getFileView(bucketId: string, fileId: string): URL {
|
|
622
|
+
if (typeof bucketId === 'undefined') {
|
|
623
|
+
throw new AppwriteException('Missing required parameter: "bucketId"');
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
if (typeof fileId === 'undefined') {
|
|
627
|
+
throw new AppwriteException('Missing required parameter: "fileId"');
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
let path = '/storage/buckets/{bucketId}/files/{fileId}/view'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
|
|
631
|
+
let payload: Payload = {};
|
|
632
|
+
|
|
633
|
+
const uri = new URL(this.client.config.endpoint + path);
|
|
634
|
+
payload['project'] = this.client.config.project;
|
|
635
|
+
|
|
636
|
+
|
|
637
|
+
for (const [key, value] of Object.entries(Service.flatten(payload))) {
|
|
638
|
+
uri.searchParams.append(key, value);
|
|
639
|
+
}
|
|
640
|
+
return uri;
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
/**
|
|
644
|
+
* Get usage stats for storage
|
|
645
|
+
*
|
|
646
|
+
*
|
|
647
|
+
* @param {string} range
|
|
648
|
+
* @throws {AppwriteException}
|
|
649
|
+
* @returns {Promise}
|
|
650
|
+
*/
|
|
651
|
+
async getUsage(range?: string): Promise<Models.UsageStorage> {
|
|
652
|
+
let path = '/storage/usage';
|
|
653
|
+
let payload: Payload = {};
|
|
654
|
+
|
|
655
|
+
if (typeof range !== 'undefined') {
|
|
656
|
+
payload['range'] = range;
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
const uri = new URL(this.client.config.endpoint + path);
|
|
660
|
+
return await this.client.call('get', uri, {
|
|
661
|
+
'content-type': 'application/json',
|
|
662
|
+
}, payload);
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
/**
|
|
666
|
+
* Get usage stats for a storage bucket
|
|
667
|
+
*
|
|
668
|
+
*
|
|
669
|
+
* @param {string} bucketId
|
|
670
|
+
* @param {string} range
|
|
671
|
+
* @throws {AppwriteException}
|
|
672
|
+
* @returns {Promise}
|
|
673
|
+
*/
|
|
674
|
+
async getBucketUsage(bucketId: string, range?: string): Promise<Models.UsageBuckets> {
|
|
675
|
+
if (typeof bucketId === 'undefined') {
|
|
676
|
+
throw new AppwriteException('Missing required parameter: "bucketId"');
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
let path = '/storage/{bucketId}/usage'.replace('{bucketId}', bucketId);
|
|
680
|
+
let payload: Payload = {};
|
|
681
|
+
|
|
682
|
+
if (typeof range !== 'undefined') {
|
|
683
|
+
payload['range'] = range;
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
const uri = new URL(this.client.config.endpoint + path);
|
|
687
|
+
return await this.client.call('get', uri, {
|
|
688
|
+
'content-type': 'application/json',
|
|
689
|
+
}, payload);
|
|
690
|
+
}
|
|
691
|
+
};
|