Skip to content

Commit 6fbd8a5

Browse files
committed
fix: for appwrite 1.4.x
1 parent 44063b8 commit 6fbd8a5

File tree

5 files changed

+81
-15
lines changed

5 files changed

+81
-15
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import { Client, Account } from "appwrite";
3333
To install with a CDN (content delivery network) add the following scripts to the bottom of your <body> tag, but before you use any Appwrite services:
3434

3535
```html
36-
<script src="https://cdn.jsdelivr.net/npm/[email protected].0"></script>
36+
<script src="https://cdn.jsdelivr.net/npm/[email protected].1"></script>
3737
```
3838

3939

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "appwrite",
33
"homepage": "https://appwrite.io/support",
44
"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": "12.0.0",
5+
"version": "12.0.1",
66
"license": "BSD-3-Clause",
77
"main": "dist/cjs/sdk.js",
88
"exports": {

src/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class Client {
102102
'x-sdk-name': 'Web',
103103
'x-sdk-platform': 'client',
104104
'x-sdk-language': 'web',
105-
'x-sdk-version': '12.0.0',
105+
'x-sdk-version': '12.0.1',
106106
'X-Appwrite-Response-Format': '1.4.0',
107107
};
108108

src/role.ts

Lines changed: 72 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,100 @@
1+
/**
2+
* Helper class to generate role strings for `Permission`.
3+
*/
14
export class Role {
5+
6+
/**
7+
* Grants access to anyone.
8+
*
9+
* This includes authenticated and unauthenticated users.
10+
*
11+
* @returns {string}
12+
*/
213
public static any(): string {
314
return 'any'
415
}
516

17+
/**
18+
* Grants access to a specific user by user ID.
19+
*
20+
* You can optionally pass verified or unverified for
21+
* `status` to target specific types of users.
22+
*
23+
* @param {string} id
24+
* @param {string} status
25+
* @returns {string}
26+
*/
627
public static user(id: string, status: string = ''): string {
7-
if(status === '') {
28+
if (status === '') {
829
return `user:${id}`
930
}
1031
return `user:${id}/${status}`
1132
}
12-
33+
34+
/**
35+
* Grants access to any authenticated or anonymous user.
36+
*
37+
* You can optionally pass verified or unverified for
38+
* `status` to target specific types of users.
39+
*
40+
* @param {string} status
41+
* @returns {string}
42+
*/
1343
public static users(status: string = ''): string {
14-
if(status === '') {
44+
if (status === '') {
1545
return 'users'
1646
}
1747
return `users/${status}`
1848
}
19-
49+
50+
/**
51+
* Grants access to any guest user without a session.
52+
*
53+
* Authenticated users don't have access to this role.
54+
*
55+
* @returns {string}
56+
*/
2057
public static guests(): string {
2158
return 'guests'
2259
}
23-
60+
61+
/**
62+
* Grants access to a team by team ID.
63+
*
64+
* You can optionally pass a role for `role` to target
65+
* team members with the specified role.
66+
*
67+
* @param {string} id
68+
* @param {string} role
69+
* @returns {string}
70+
*/
2471
public static team(id: string, role: string = ''): string {
25-
if(role === '') {
72+
if (role === '') {
2673
return `team:${id}`
2774
}
2875
return `team:${id}/${role}`
2976
}
3077

78+
/**
79+
* Grants access to a specific member of a team.
80+
*
81+
* When the member is removed from the team, they will
82+
* no longer have access.
83+
*
84+
* @param {string} id
85+
* @returns {string}
86+
*/
3187
public static member(id: string): string {
3288
return `member:${id}`
3389
}
90+
91+
/**
92+
* Grants access to a user with the specified label.
93+
*
94+
* @param {string} name
95+
* @returns {string}
96+
*/
97+
public static label(name: string): string {
98+
return `label:${name}`
99+
}
34100
}

src/services/storage.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,15 @@ export class Storage extends Service {
118118
let id = undefined;
119119
let response = undefined;
120120

121-
const headers: { [header: string]: string } = {
121+
const apiHeaders: { [header: string]: string } = {
122122
'content-type': 'multipart/form-data',
123123
}
124124

125125
let counter = 0;
126126
const totalCounters = Math.ceil(size / Service.CHUNK_SIZE);
127127
if(fileId != 'unique()') {
128128
try {
129-
response = await this.client.call('GET', new URL(this.client.config.endpoint + apiPath + '/' + fileId), headers);
129+
response = await this.client.call('GET', new URL(this.client.config.endpoint + apiPath + '/' + fileId), apiHeaders);
130130
counter = response.chunksUploaded;
131131
} catch(e) {
132132
}
@@ -136,16 +136,16 @@ export class Storage extends Service {
136136
const start = (counter * Service.CHUNK_SIZE);
137137
const end = Math.min((((counter * Service.CHUNK_SIZE) + Service.CHUNK_SIZE) - 1), size);
138138

139-
headers['content-range'] = 'bytes ' + start + '-' + end + '/' + size
139+
apiHeaders['content-range'] = 'bytes ' + start + '-' + end + '/' + size
140140

141141
if (id) {
142-
headers['x-appwrite-id'] = id;
142+
apiHeaders['x-appwrite-id'] = id;
143143
}
144144

145145
const stream = file.slice(start, end + 1);
146146
payload['file'] = new File([stream], file.name);
147147

148-
response = await this.client.call('post', uri, headers, payload);
148+
response = await this.client.call('post', uri, apiHeaders, payload);
149149

150150
if (!id) {
151151
id = response['$id'];
@@ -154,7 +154,7 @@ export class Storage extends Service {
154154
if (onProgress) {
155155
onProgress({
156156
$id: response.$id,
157-
progress: Math.min((counter + 1) * Service.CHUNK_SIZE - 1, size) / size * 100,
157+
progress: Math.min((counter + 1) * Service.CHUNK_SIZE, size) / size * 100,
158158
sizeUploaded: end,
159159
chunksTotal: response.chunksTotal,
160160
chunksUploaded: response.chunksUploaded

0 commit comments

Comments
 (0)