mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-10-01 14:41:32 +00:00
* Revert "AAE-30882 Replace superagent (#11134)"
This reverts commit a347b20f20
.
* AAE-0000 - Fixed lock for cli and adf
This commit is contained in:
@@ -51,69 +51,6 @@ export class UploadApi extends NodesApi {
|
||||
|
||||
formParam = Object.assign(formParam, opts);
|
||||
|
||||
const originalPromise = this.createNode(rootFolderId, nodeBody, opts, formParam);
|
||||
|
||||
let isAborted = false;
|
||||
let abortReject: (reason?: any) => void;
|
||||
|
||||
// Create a new promise that can be aborted
|
||||
const abortablePromise = new Promise((resolve, reject) => {
|
||||
abortReject = reject;
|
||||
|
||||
if (isAborted) {
|
||||
reject(new Error('Upload aborted'));
|
||||
return;
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
if (!isAborted && typeof (abortablePromise as any).emit === 'function') {
|
||||
(abortablePromise as any).emit('progress', { loaded: 25, total: 100 });
|
||||
}
|
||||
}, 10);
|
||||
|
||||
setTimeout(() => {
|
||||
if (!isAborted && typeof (abortablePromise as any).emit === 'function') {
|
||||
(abortablePromise as any).emit('progress', { loaded: 50, total: 100 });
|
||||
}
|
||||
}, 50);
|
||||
|
||||
originalPromise
|
||||
.then((result) => {
|
||||
if (!isAborted) {
|
||||
if (typeof (abortablePromise as any).emit === 'function') {
|
||||
(abortablePromise as any).emit('progress', { loaded: 100, total: 100 });
|
||||
}
|
||||
resolve(result);
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
if (!isAborted) {
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Object.setPrototypeOf(abortablePromise, Object.getPrototypeOf(originalPromise));
|
||||
Object.getOwnPropertyNames(originalPromise).forEach((key) => {
|
||||
if (key !== 'then' && key !== 'catch' && key !== 'finally') {
|
||||
(abortablePromise as any)[key] = (originalPromise as any)[key];
|
||||
}
|
||||
});
|
||||
|
||||
(abortablePromise as any).abort = () => {
|
||||
if (!isAborted) {
|
||||
isAborted = true;
|
||||
|
||||
if (typeof (abortablePromise as any).emit === 'function') {
|
||||
(abortablePromise as any).emit('abort');
|
||||
}
|
||||
|
||||
if (abortReject) {
|
||||
abortReject(new Error('Upload aborted'));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return abortablePromise;
|
||||
return this.createNode(rootFolderId, nodeBody, opts, formParam);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user