Skip to content

Commit 284290a

Browse files
fix: realtime events payload
1 parent bae5430 commit 284290a

File tree

5 files changed

+34
-6
lines changed

5 files changed

+34
-6
lines changed

docs/examples/functions/create-deployment.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ client
1212
;
1313

1414

15-
let promise = functions.createDeployment('[FUNCTION_ID]', '[ENTRYPOINT]', new File([fileBlob], 'file.png'), false);
15+
let promise = functions.createDeployment('[FUNCTION_ID]', '[ENTRYPOINT]', 'file.png', false);
1616

1717
promise.then(function (response) {
1818
console.log(response);

docs/examples/storage/create-file.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ client
1212
;
1313

1414

15-
let promise = storage.createFile('[BUCKET_ID]', '[FILE_ID]', new File([fileBlob], 'file.png'));
15+
let promise = storage.createFile('[BUCKET_ID]', '[FILE_ID]', 'file.png');
1616

1717
promise.then(function (response) {
1818
console.log(response);

src/models.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ export namespace Models {
277277
/**
278278
* Collection attributes.
279279
*/
280-
attributes: string[];
280+
attributes: (AttributeBoolean | AttributeInteger | AttributeFloat | AttributeEmail | AttributeEnum | AttributeUrl | AttributeIp | AttributeString)[];
281281
/**
282282
* Collection indexes.
283283
*/
@@ -294,7 +294,7 @@ export namespace Models {
294294
/**
295295
* List of attributes.
296296
*/
297-
attributes: string[];
297+
attributes: (AttributeBoolean | AttributeInteger | AttributeFloat | AttributeEmail | AttributeEnum | AttributeUrl | AttributeIp | AttributeString)[];
298298
}
299299
/**
300300
* AttributeString

src/services/functions.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,8 @@ export class Functions extends Service {
371371
headers['x-appwrite-id'] = id;
372372
}
373373

374-
const totalBuffer = new Uint8Array(Client.CHUNK_SIZE);
374+
let totalBuffer = new Uint8Array(Client.CHUNK_SIZE);
375+
let lastBufferIndex = -1;
375376

376377
for (let blockIndex = 0; blockIndex < Client.CHUNK_SIZE / Client.DENO_READ_CHUNK_SIZE; blockIndex++) {
377378
const buf = new Uint8Array(Client.DENO_READ_CHUNK_SIZE);
@@ -384,7 +385,20 @@ export class Functions extends Service {
384385

385386
for (let byteIndex = 0; byteIndex < Client.DENO_READ_CHUNK_SIZE; byteIndex++) {
386387
totalBuffer[(blockIndex * Client.DENO_READ_CHUNK_SIZE) + byteIndex] = buf[byteIndex];
388+
389+
if(buf[byteIndex] !== 0) {
390+
lastBufferIndex = (blockIndex * Client.DENO_READ_CHUNK_SIZE) + byteIndex;
391+
}
392+
}
393+
}
394+
395+
// Shrink empty bytes
396+
if(lastBufferIndex !== -1) {
397+
const newTotalBuffer = new Uint8Array(lastBufferIndex + 1);
398+
for(let index = 0; index <= lastBufferIndex; index++) {
399+
newTotalBuffer[index] = totalBuffer[index];
387400
}
401+
totalBuffer = newTotalBuffer;
388402
}
389403

390404
payload['code'] = new File([totalBuffer], basename(code));

src/services/storage.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,8 @@ export class Storage extends Service {
386386
headers['x-appwrite-id'] = id;
387387
}
388388

389-
const totalBuffer = new Uint8Array(Client.CHUNK_SIZE);
389+
let totalBuffer = new Uint8Array(Client.CHUNK_SIZE);
390+
let lastBufferIndex = -1;
390391

391392
for (let blockIndex = 0; blockIndex < Client.CHUNK_SIZE / Client.DENO_READ_CHUNK_SIZE; blockIndex++) {
392393
const buf = new Uint8Array(Client.DENO_READ_CHUNK_SIZE);
@@ -399,7 +400,20 @@ export class Storage extends Service {
399400

400401
for (let byteIndex = 0; byteIndex < Client.DENO_READ_CHUNK_SIZE; byteIndex++) {
401402
totalBuffer[(blockIndex * Client.DENO_READ_CHUNK_SIZE) + byteIndex] = buf[byteIndex];
403+
404+
if(buf[byteIndex] !== 0) {
405+
lastBufferIndex = (blockIndex * Client.DENO_READ_CHUNK_SIZE) + byteIndex;
406+
}
407+
}
408+
}
409+
410+
// Shrink empty bytes
411+
if(lastBufferIndex !== -1) {
412+
const newTotalBuffer = new Uint8Array(lastBufferIndex + 1);
413+
for(let index = 0; index <= lastBufferIndex; index++) {
414+
newTotalBuffer[index] = totalBuffer[index];
402415
}
416+
totalBuffer = newTotalBuffer;
403417
}
404418

405419
payload['file'] = new File([totalBuffer], basename(file));

0 commit comments

Comments
 (0)