Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Appwrite Node.js SDK

![License](https://img.shields.io/github/license/appwrite/sdk-for-node.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 lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ class Client {
this.headers = {
'accept-encoding': '*',
'content-type': '',
'user-agent' : `AppwriteNodeJSSDK/10.0.0 (${os.type()}; ${os.version()}; ${os.arch()})`,
'user-agent' : `AppwriteNodeJSSDK/10.0.1 (${os.type()}; ${os.version()}; ${os.arch()})`,
'x-sdk-name': 'Node.js',
'x-sdk-platform': 'server',
'x-sdk-language': 'nodejs',
'x-sdk-version': '10.0.0',
'x-sdk-version': '10.0.1',
'X-Appwrite-Response-Format' : '1.4.0',
};
this.selfSigned = false;
Expand Down
77 changes: 74 additions & 3 deletions lib/role.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,102 @@
/**
* Helper class to generate role strings for `Permission`.
*/
class Role {

/**
* Grants access to anyone.
*
* This includes authenticated and unauthenticated users.
*
* @returns {string}
*/
static any = () => {
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}
*/
static user = (id, status = '') => {
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}
*/
static users = (status = '') => {
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}
*/
static guests = () => {
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}
*/
static team = (id, role = '') => {
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}
*/
static member = (id) => {
return 'member:' + id
}

/**
* Grants access to a user with the specified label.
*
* @param {string} name
* @returns {string}
*/
static label = (name) => {
return 'label:' + name;
}
}

module.exports = Role;
19 changes: 12 additions & 7 deletions lib/services/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ class Functions extends Service {

const size = code.size;

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

Expand All @@ -450,20 +450,24 @@ class Functions extends Service {
}

const start = currentChunkStart;
const end = Math.min(((start + client.CHUNK_SIZE) - 1), size);
const end = currentChunkStart + currentChunkSize - 1;

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

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

const stream = Stream.Readable.from(currentChunk);
payload['code'] = { type: 'file', file: stream, filename: code.filename };
payload['code'] = {
type: 'file',
file: currentChunk,
filename: code.filename,
size: currentChunkSize
};

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

if (!id) {
id = response['$id'];
Expand Down Expand Up @@ -502,6 +506,7 @@ class Functions extends Service {
if(chunkSize + currentChunkSize == client.CHUNK_SIZE) {
// Upload chunk
currentChunk = Buffer.concat([currentChunk, chunk]);
currentChunkSize = Buffer.byteLength(currentChunk);
await uploadChunk();
currentChunk = Buffer.from('');
currentChunkSize = 0;
Expand Down
21 changes: 13 additions & 8 deletions lib/services/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ class Storage extends Service {

const size = file.size;

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

Expand All @@ -336,7 +336,7 @@ 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 @@ -354,20 +354,24 @@ class Storage extends Service {
}

const start = currentChunkStart;
const end = Math.min(((start + client.CHUNK_SIZE) - 1), size);
const end = currentChunkStart + currentChunkSize - 1;

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

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

const stream = Stream.Readable.from(currentChunk);
payload['file'] = { type: 'file', file: stream, filename: file.filename };
payload['file'] = {
type: 'file',
file: currentChunk,
filename: file.filename,
size: currentChunkSize
};

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

if (!id) {
id = response['$id'];
Expand Down Expand Up @@ -406,6 +410,7 @@ class Storage extends Service {
if(chunkSize + currentChunkSize == client.CHUNK_SIZE) {
// Upload chunk
currentChunk = Buffer.concat([currentChunk, chunk]);
currentChunkSize = Buffer.byteLength(currentChunk);
await uploadChunk();
currentChunk = Buffer.from('');
currentChunkSize = 0;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "node-appwrite",
"homepage": "https://appwrite.io/support",
"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",
"version": "10.0.0",
"version": "10.0.1",
"license": "BSD-3-Clause",
"main": "./index.js",
"types": "./index.d.ts",
Expand Down