Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: patch updates for appwrite 1.4.1 #15

Merged
merged 2 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ export class Client {
endpoint: string = 'https://HOSTNAME/v1';
headers: Payload = {
'content-type': '',
'user-agent' : `AppwriteDenoSDK/8.0.0 (${Deno.build.os}; ${Deno.build.arch})`,
'user-agent' : `AppwriteDenoSDK/8.0.1 (${Deno.build.os}; ${Deno.build.arch})`,
'x-sdk-name': 'Deno',
'x-sdk-platform': 'server',
'x-sdk-language': 'deno',
'x-sdk-version': '8.0.0',
'x-sdk-version': '8.0.1',
'X-Appwrite-Response-Format':'1.4.0',
};

Expand Down
78 changes: 72 additions & 6 deletions src/role.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,100 @@
/**
* Helper class to generate role strings for `Permission`.
*/
export class Role {

/**
* Grants access to anyone.
*
* This includes authenticated and unauthenticated users.
*
* @returns {string}
*/
public static any(): string {
return 'any'
}

/**
* Grants access to a specific user by user ID.
*
* You can optionally pass verified or unverified for
* `status` to target specific types of users.
*
* @param {string} id
* @param {string} status
* @returns {string}
*/
public static user(id: string, status: string = ''): string {
if(status === '') {
if (status === '') {
return `user:${id}`
}
return `user:${id}/${status}`
}


/**
* Grants access to any authenticated or anonymous user.
*
* You can optionally pass verified or unverified for
* `status` to target specific types of users.
*
* @param {string} status
* @returns {string}
*/
public static users(status: string = ''): string {
if(status === '') {
if (status === '') {
return 'users'
}
return `users/${status}`
}


/**
* Grants access to any guest user without a session.
*
* Authenticated users don't have access to this role.
*
* @returns {string}
*/
public static guests(): string {
return 'guests'
}


/**
* Grants access to a team by team ID.
*
* You can optionally pass a role for `role` to target
* team members with the specified role.
*
* @param {string} id
* @param {string} role
* @returns {string}
*/
public static team(id: string, role: string = ''): string {
if(role === '') {
if (role === '') {
return `team:${id}`
}
return `team:${id}/${role}`
}

/**
* Grants access to a specific member of a team.
*
* When the member is removed from the team, they will
* no longer have access.
*
* @param {string} id
* @returns {string}
*/
public static member(id: string): string {
return `member:${id}`
}

/**
* Grants access to a user with the specified label.
*
* @param {string} name
* @returns {string}
*/
public static label(name: string): string {
return `label:${name}`
}
}
8 changes: 4 additions & 4 deletions src/services/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ export class Functions extends Service {

const size = code.size;

const headers: { [header: string]: string } = {
const apiHeaders: { [header: string]: string } = {
'content-type': 'multipart/form-data',
};

Expand All @@ -412,7 +412,7 @@ export class Functions extends Service {
const end = start + currentPosition;

if(!lastUpload || currentChunk !== 1) {
headers['content-range'] = 'bytes ' + start + '-' + end + '/' + size;
apiHeaders['content-range'] = 'bytes ' + start + '-' + end + '/' + size;
}

let uploadableChunkTrimmed: Uint8Array;
Expand All @@ -427,12 +427,12 @@ export class Functions extends Service {
}

if (id) {
headers['x-appwrite-id'] = id;
apiHeaders['x-appwrite-id'] = id;
}

payload['code'] = { type: 'file', file: new File([uploadableChunkTrimmed], code.filename), filename: code.filename };

response = await this.client.call('post', apiPath, headers, payload);
response = await this.client.call('post', apiPath, apiHeaders, payload);

if (!id) {
id = response['$id'];
Expand Down
10 changes: 5 additions & 5 deletions src/services/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ export class Storage extends Service {

const size = file.size;

const headers: { [header: string]: string } = {
const apiHeaders: { [header: string]: string } = {
'content-type': 'multipart/form-data',
};

Expand All @@ -315,7 +315,7 @@ export class Storage extends Service {

if(fileId != 'unique()') {
try {
response = await this.client.call('get', apiPath + '/' + fileId, headers);
response = await this.client.call('get', apiPath + '/' + fileId, apiHeaders);
chunksUploaded = response.chunksUploaded;
} catch(e) {
}
Expand All @@ -334,7 +334,7 @@ export class Storage extends Service {
const end = start + currentPosition;

if(!lastUpload || currentChunk !== 1) {
headers['content-range'] = 'bytes ' + start + '-' + end + '/' + size;
apiHeaders['content-range'] = 'bytes ' + start + '-' + end + '/' + size;
}

let uploadableChunkTrimmed: Uint8Array;
Expand All @@ -349,12 +349,12 @@ export class Storage extends Service {
}

if (id) {
headers['x-appwrite-id'] = id;
apiHeaders['x-appwrite-id'] = id;
}

payload['file'] = { type: 'file', file: new File([uploadableChunkTrimmed], file.filename), filename: file.filename };

response = await this.client.call('post', apiPath, headers, payload);
response = await this.client.call('post', apiPath, apiHeaders, payload);

if (!id) {
id = response['$id'];
Expand Down