Skip to content

Commit 59f2ea7

Browse files
committed
chore: bug fixes for Apwrite 1.4.2
1 parent 5a26b28 commit 59f2ea7

File tree

4 files changed

+17
-31
lines changed

4 files changed

+17
-31
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Appwrite Web SDK
22

33
![License](https://img.shields.io/github/license/appwrite/sdk-for-web.svg?style=flat-square)
4-
![Version](https://img.shields.io/badge/api%20version-1.4.1-blue.svg?style=flat-square)
4+
![Version](https://img.shields.io/badge/api%20version-1.4.2-blue.svg?style=flat-square)
55
[![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator)
66
[![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite)
77
[![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord)

docs/examples/teams/create-membership.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ client
99
.setProject('5df5acd0d48c2') // Your project ID
1010
;
1111

12-
const promise = teams.createMembership('[TEAM_ID]', [], 'https://example.com');
12+
const promise = teams.createMembership('[TEAM_ID]', []);
1313

1414
promise.then(function (response) {
1515
console.log(response); // Success

src/services/storage.ts

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -111,57 +111,47 @@ export class Storage extends Service {
111111

112112
if (size <= Service.CHUNK_SIZE) {
113113
return await this.client.call('post', uri, {
114-
115114
'content-type': 'multipart/form-data',
116115
}, payload);
117116
}
118-
let id = undefined;
119-
let response = undefined;
120117

121118
const apiHeaders: { [header: string]: string } = {
122119
'content-type': 'multipart/form-data',
123120
}
124121

125-
let counter = 0;
126-
const totalCounters = Math.ceil(size / Service.CHUNK_SIZE);
122+
let offset = 0;
123+
let response = undefined;
127124
if(fileId != 'unique()') {
128125
try {
129126
response = await this.client.call('GET', new URL(this.client.config.endpoint + apiPath + '/' + fileId), apiHeaders);
130-
counter = response.chunksUploaded;
127+
offset = response.chunksUploaded * Service.CHUNK_SIZE;
131128
} catch(e) {
132129
}
133130
}
134131

135-
for (counter; counter < totalCounters; counter++) {
136-
const start = (counter * Service.CHUNK_SIZE);
137-
const end = Math.min((((counter * Service.CHUNK_SIZE) + Service.CHUNK_SIZE) - 1), size);
138-
139-
apiHeaders['content-range'] = 'bytes ' + start + '-' + end + '/' + size
132+
while (offset < size) {
133+
let end = Math.min(offset + Service.CHUNK_SIZE - 1, size - 1);
140134

141-
if (id) {
142-
apiHeaders['x-appwrite-id'] = id;
135+
apiHeaders['content-range'] = 'bytes ' + offset + '-' + end + '/' + size;
136+
if (response && response.$id) {
137+
apiHeaders['x-appwrite-id'] = response.$id;
143138
}
144139

145-
const stream = file.slice(start, end + 1);
146-
payload['file'] = new File([stream], file.name);
147-
140+
const chunk = file.slice(offset, end + 1);
141+
payload['file'] = new File([chunk], file.name);
148142
response = await this.client.call('post', uri, apiHeaders, payload);
149143

150-
if (!id) {
151-
id = response['$id'];
152-
}
153-
154144
if (onProgress) {
155145
onProgress({
156146
$id: response.$id,
157-
progress: Math.min((counter + 1) * Service.CHUNK_SIZE, size) / size * 100,
158-
sizeUploaded: end,
147+
progress: (offset / size) * 100,
148+
sizeUploaded: offset,
159149
chunksTotal: response.chunksTotal,
160150
chunksUploaded: response.chunksUploaded
161151
});
162152
}
153+
offset += Service.CHUNK_SIZE;
163154
}
164-
165155
return response;
166156
}
167157

src/services/teams.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -222,15 +222,15 @@ export class Teams extends Service {
222222
*
223223
* @param {string} teamId
224224
* @param {string[]} roles
225-
* @param {string} url
226225
* @param {string} email
227226
* @param {string} userId
228227
* @param {string} phone
228+
* @param {string} url
229229
* @param {string} name
230230
* @throws {AppwriteException}
231231
* @returns {Promise}
232232
*/
233-
async createMembership(teamId: string, roles: string[], url: string, email?: string, userId?: string, phone?: string, name?: string): Promise<Models.Membership> {
233+
async createMembership(teamId: string, roles: string[], email?: string, userId?: string, phone?: string, url?: string, name?: string): Promise<Models.Membership> {
234234
if (typeof teamId === 'undefined') {
235235
throw new AppwriteException('Missing required parameter: "teamId"');
236236
}
@@ -239,10 +239,6 @@ export class Teams extends Service {
239239
throw new AppwriteException('Missing required parameter: "roles"');
240240
}
241241

242-
if (typeof url === 'undefined') {
243-
throw new AppwriteException('Missing required parameter: "url"');
244-
}
245-
246242
const apiPath = '/teams/{teamId}/memberships'.replace('{teamId}', teamId);
247243
const payload: Payload = {};
248244

0 commit comments

Comments
 (0)