Skip to content

Commit

Permalink
Merge pull request #15 from appwrite/dev
Browse files Browse the repository at this point in the history
fix: patch updates for appwrite 1.4.1
  • Loading branch information
abnegate committed Sep 1, 2023
2 parents 37abd13 + 5162d6b commit 631f3d5
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Appwrite Deno SDK

![License](https://img.shields.io/github/license/appwrite/sdk-for-deno.svg?style=flat-square)
![Version](https://img.shields.io/badge/api%20version-1.4.0-blue.svg?style=flat-square)
![Version](https://img.shields.io/badge/api%20version-1.4.1-blue.svg?style=flat-square)
[![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator)
[![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite)
[![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord)
Expand Down
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

0 comments on commit 631f3d5

Please sign in to comment.