Skip to content

Commit

Permalink
fix(promises): Remove finally from promises, there was some problems …
Browse files Browse the repository at this point in the history
…with polyfils
  • Loading branch information
pcholuj committed Jun 7, 2019
1 parent 2a68edb commit 2fab112
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 46 deletions.
8 changes: 1 addition & 7 deletions manual_tests/upload_new.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ import { getFile } from '../src/lib/api/upload';

const createFile = (size = 44320) => Buffer.alloc(size);

const fs = new Client('API_KEY', {
cname: 'rc.filepickerapp.com',
});
const fs = new Client('APEkwxKMZTsWNIP0XQsv2z');

// fs.multiupload(
// [
Expand All @@ -45,10 +43,6 @@ const fs = new Client('API_KEY', {
try {
fs.upload(createFile(), {}, {
filename: 'HR-mary-oo',
sanitizer: {
exclude: ['m'],
replacement: 'hrr',
}
}).then((res) => {
console.info('Upload done!', res);
});
Expand Down
41 changes: 11 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 14 additions & 3 deletions src/lib/api/upload/uploaders/s3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,9 @@ export class S3Uploader extends UploaderAbstract {
}

return this.uploadNextChunk(id, partNumber, chunkSize);

part = null;
chunk = null;
})
.catch(err => {
// reset progress on failed upload
Expand All @@ -547,8 +550,7 @@ export class S3Uploader extends UploaderAbstract {
}

return Promise.reject(new FilestackError('Cannot upload file part', err.data, FilestackErrorType.REQUEST));
})
.finally(() => {

part = null;
chunk = null;
});
Expand Down Expand Up @@ -758,7 +760,16 @@ export class S3Uploader extends UploaderAbstract {
*/
private setPartData(id: string, partNumber: number, key: string, value: any) {
debug(`[${id}] Set ${key} = ${value} for part ${partNumber}`);
this.getPayloadById(id).parts[partNumber][key] = value;

const payload = this.getPayloadById(id);

/* istanbul ignore next */
if (!payload) {
debug(`[${id}] Cannot set ${key} = ${value} for part ${partNumber}`);
return;
}

payload.parts[partNumber][key] = value;
}

/**
Expand Down
8 changes: 2 additions & 6 deletions src/lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,9 +384,7 @@ export class Client extends EventEmitter {

upload.on('error', (e) => this.emit('uploadError', e));

return upload.upload(file).finally(() => {
upload = null;
});
return upload.upload(file);
}

/**
Expand Down Expand Up @@ -436,8 +434,6 @@ export class Client extends EventEmitter {

upload.on('error', (e) => this.emit('uploadError', e));

return upload.multiupload(file).finally(() => {
upload = null;
});
return upload.multiupload(file);
}
}

0 comments on commit 2fab112

Please sign in to comment.