Skip to content

Commit d6f5fe4

Browse files
Merge pull request #694 from appwrite/1.4.x
Related to Appwrite 1.4.x release
2 parents 06ea25a + 26b4f06 commit d6f5fe4

File tree

43 files changed

+688
-61
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+688
-61
lines changed

templates/android/library/src/main/java/io/appwrite/Client.kt.twig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ class Client @JvmOverloads constructor(
374374
responseType = Map::class.java,
375375
)
376376
val chunksUploaded = current["chunksUploaded"] as Long
377-
offset = (chunksUploaded * CHUNK_SIZE).coerceAtMost(size)
377+
offset = chunksUploaded * CHUNK_SIZE
378378
}
379379

380380
while (offset < size) {
@@ -385,7 +385,7 @@ class Client @JvmOverloads constructor(
385385
}
386386
"bytes" -> {
387387
val end = if (offset + CHUNK_SIZE < size) {
388-
offset + CHUNK_SIZE
388+
offset + CHUNK_SIZE - 1
389389
} else {
390390
size - 1
391391
}
@@ -405,7 +405,7 @@ class Client @JvmOverloads constructor(
405405
)
406406

407407
headers["Content-Range"] =
408-
"bytes $offset-${((offset + CHUNK_SIZE) - 1).coerceAtMost(size)}/$size"
408+
"bytes $offset-${((offset + CHUNK_SIZE) - 1).coerceAtMost(size - 1)}/$size"
409409

410410
result = call(
411411
method = "POST",
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,72 @@
11
package {{ sdk.namespace | caseDot }}
22

3+
/**
4+
* Helper class to generate role strings for [Permission].
5+
*/
36
class Role {
47
companion object {
8+
9+
/**
10+
* Grants access to anyone.
11+
*
12+
* This includes authenticated and unauthenticated users.
13+
*/
514
fun any(): String = "any"
615

16+
/**
17+
* Grants access to a specific user by user ID.
18+
*
19+
* You can optionally pass verified or unverified for
20+
* [status] to target specific types of users.
21+
*/
722
fun user(id: String, status: String = ""): String = if(status.isEmpty()) {
823
"user:$id"
924
} else {
1025
"user:$id/$status"
1126
}
1227

28+
/**
29+
* Grants access to any authenticated or anonymous user.
30+
*
31+
* You can optionally pass verified or unverified for
32+
* [status] to target specific types of users.
33+
*/
1334
fun users(status: String = ""): String = if(status.isEmpty()) {
1435
"users"
1536
} else {
1637
"users/$status"
1738
}
1839

40+
/**
41+
* Grants access to any guest user without a session.
42+
*
43+
* Authenticated users don't have access to this role.
44+
*/
1945
fun guests(): String = "guests"
2046

47+
/**
48+
* Grants access to a team by team ID.
49+
*
50+
* You can optionally pass a role for [role] to target
51+
* team members with the specified role.
52+
*/
2153
fun team(id: String, role: String = ""): String = if(role.isEmpty()) {
2254
"team:$id"
2355
} else {
2456
"team:$id/$role"
2557
}
2658

59+
/**
60+
* Grants access to a specific member of a team.
61+
*
62+
* When the member is removed from the team, they will
63+
* no longer have access.
64+
*/
2765
fun member(id: String): String = "member:$id"
66+
67+
/**
68+
* Grants access to a user with the specified label.
69+
*/
70+
fun label(name: String): String = "label:$name"
2871
}
2972
}

templates/cli/lib/commands/command.js.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ const {{ service.name | caseLower }}{{ method.name | caseUcfirst }} = async ({ {
164164

165165
for (counter; counter < totalCounters; counter++) {
166166
const start = (counter * libClient.CHUNK_SIZE);
167-
const end = Math.min((((counter * libClient.CHUNK_SIZE) + libClient.CHUNK_SIZE) - 1), size);
167+
const end = Math.min((((counter * libClient.CHUNK_SIZE) + libClient.CHUNK_SIZE) - 1), size - 1);
168168

169169
apiHeaders['content-range'] = 'bytes ' + start + '-' + end + '/' + size;
170170

templates/dart/lib/role.dart.twig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,9 @@ class Role {
5858
static String member(String id) {
5959
return 'member:$id';
6060
}
61+
62+
/// Grants access to a user with the specified label.
63+
static String label(String name) {
64+
return 'label:$name';
65+
}
6166
}

templates/dart/lib/src/client_browser.dart.twig

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,18 +114,18 @@ class ClientBrowser extends ClientBase with ClientMixin {
114114
headers: headers,
115115
);
116116
final int chunksUploaded = res.data['chunksUploaded'] as int;
117-
offset = min(size, chunksUploaded * CHUNK_SIZE);
117+
offset = chunksUploaded * CHUNK_SIZE;
118118
} on {{spec.title | caseUcfirst}}Exception catch (_) {}
119119
}
120120

121121
while (offset < size) {
122-
List<int> chunk;
123-
final end = min(offset + CHUNK_SIZE, size);
122+
var chunk;
123+
final end = min(offset + CHUNK_SIZE - 1, size - 1);
124124
chunk = file.bytes!.getRange(offset, end).toList();
125125
params[paramName] =
126126
http.MultipartFile.fromBytes(paramName, chunk, filename: file.filename);
127127
headers['content-range'] =
128-
'bytes $offset-${min<int>(((offset + CHUNK_SIZE) - 1), size)}/$size';
128+
'bytes $offset-${min<int>((offset + CHUNK_SIZE - 1), size - 1)}/$size';
129129
res = await call(HttpMethod.post,
130130
path: path, headers: headers, params: params);
131131
offset += CHUNK_SIZE;
@@ -134,8 +134,8 @@ class ClientBrowser extends ClientBase with ClientMixin {
134134
}
135135
final progress = UploadProgress(
136136
$id: res.data['\$id'] ?? '',
137-
progress: min(offset - 1, size) / size * 100,
138-
sizeUploaded: min(offset - 1, size),
137+
progress: min(offset, size) / size * 100,
138+
sizeUploaded: min(offset, size),
139139
chunksTotal: res.data['chunksTotal'] ?? 0,
140140
chunksUploaded: res.data['chunksUploaded'] ?? 0,
141141
);

templates/dart/lib/src/client_io.dart.twig

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ class ClientIO extends ClientBase with ClientMixin {
143143
headers: headers,
144144
);
145145
final int chunksUploaded = res.data['chunksUploaded'] as int;
146-
offset = min(size, chunksUploaded * CHUNK_SIZE);
146+
offset = chunksUploaded * CHUNK_SIZE;
147147
} on {{spec.title | caseUcfirst}}Exception catch (_) {}
148148
}
149149

@@ -156,7 +156,7 @@ class ClientIO extends ClientBase with ClientMixin {
156156
while (offset < size) {
157157
List<int> chunk = [];
158158
if (file.bytes != null) {
159-
final end = min(offset + CHUNK_SIZE-1, size-1);
159+
final end = min(offset + CHUNK_SIZE - 1, size - 1);
160160
chunk = file.bytes!.getRange(offset, end).toList();
161161
} else {
162162
raf!.setPositionSync(offset);
@@ -165,7 +165,7 @@ class ClientIO extends ClientBase with ClientMixin {
165165
params[paramName] =
166166
http.MultipartFile.fromBytes(paramName, chunk, filename: file.filename);
167167
headers['content-range'] =
168-
'bytes $offset-${min<int>(((offset + CHUNK_SIZE) - 1), size)}/$size';
168+
'bytes $offset-${min<int>((offset + CHUNK_SIZE - 1), size - 1)}/$size';
169169
res = await call(HttpMethod.post,
170170
path: path, headers: headers, params: params);
171171
offset += CHUNK_SIZE;
@@ -174,8 +174,8 @@ class ClientIO extends ClientBase with ClientMixin {
174174
}
175175
final progress = UploadProgress(
176176
$id: res.data['\$id'] ?? '',
177-
progress: min(offset - 1, size) / size * 100,
178-
sizeUploaded: min(offset - 1, size),
177+
progress: min(offset, size) / size * 100,
178+
sizeUploaded: min(offset, size),
179179
chunksTotal: res.data['chunksTotal'] ?? 0,
180180
chunksUploaded: res.data['chunksUploaded'] ?? 0,
181181
);

templates/dart/test/role_test.dart.twig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,10 @@ void main() {
5353
expect(Role.member('custom'), 'member:custom');
5454
});
5555
});
56+
57+
group('label()', () {
58+
test('returns label', () {
59+
expect(Role.label('admin'), 'label:admin');
60+
});
61+
});
5662
}

templates/deno/src/role.ts.twig

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
}

templates/dotnet/base/requests/file.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
return _client.ChunkedUpload(
1010
apiPath,
1111
apiHeaders,
12-
parameters,
12+
apiParameters,
1313
{%~ if method.responseModel %}
1414
Convert,
1515
{%~ endif %}

templates/dotnet/src/Appwrite/Client.cs.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ namespace {{ spec.title | caseUcfirst }}
354354
parameters[paramName] = content;
355355

356356
headers["Content-Range"] =
357-
$"bytes {offset}-{Math.Min(offset + ChunkSize - 1, size)}/{size}";
357+
$"bytes {offset}-{Math.Min(offset + ChunkSize - 1, size - 1)}/{size}";
358358

359359
result = await Call<Dictionary<string, object?>>(
360360
method: "POST",

0 commit comments

Comments
 (0)