diff --git a/app/lib/methods/helpers/fileUpload.ts b/app/lib/methods/helpers/fileUpload.ts index ad77c3215..d711d095b 100644 --- a/app/lib/methods/helpers/fileUpload.ts +++ b/app/lib/methods/helpers/fileUpload.ts @@ -6,7 +6,7 @@ export interface IFileUpload { data?: any; } -class Upload { +export class Upload { public xhr: XMLHttpRequest; public formData: FormData; @@ -34,20 +34,20 @@ class Upload { } } - public then(callback: (param: { respInfo: XMLHttpRequest }) => XMLHttpRequest) { + public then(callback: (param: { respInfo: XMLHttpRequest }) => void): void { this.xhr.onload = () => callback({ respInfo: this.xhr }); this.xhr.send(this.formData); } - public catch(callback: ((this: XMLHttpRequest, ev: ProgressEvent) => any) | null) { + public catch(callback: ((this: XMLHttpRequest, ev: ProgressEvent) => any) | null): void { this.xhr.onerror = callback; } - public uploadProgress(callback: (param: number, arg1: number) => any) { + public uploadProgress(callback: (param: number, arg1: number) => any): void { this.xhr.upload.onprogress = ({ total, loaded }) => callback(loaded, total); } - public cancel() { + public cancel(): Promise { this.xhr.abort(); return Promise.resolve(); } diff --git a/app/lib/methods/sendFileMessage.ts b/app/lib/methods/sendFileMessage.ts index fcd87dd8b..750faba7a 100644 --- a/app/lib/methods/sendFileMessage.ts +++ b/app/lib/methods/sendFileMessage.ts @@ -10,11 +10,11 @@ import database from '../database'; import { Encryption } from '../encryption'; import { store } from '../store/auxStore'; import { compareServerVersion } from './helpers'; -import type { IFileUpload } from './helpers/fileUpload'; +import type { IFileUpload, Upload } from './helpers/fileUpload'; import FileUpload from './helpers/fileUpload'; import log from './helpers/log'; -const uploadQueue: { [index: string]: any } = {}; +const uploadQueue: { [index: string]: Upload } = {}; const getUploadPath = (path: string, rid: string) => `${path}-${rid}`; @@ -51,7 +51,7 @@ export function sendFileMessage( server: string, user: Partial>, isForceTryAgain?: boolean -): Promise { +): Promise { return new Promise(async (resolve, reject) => { try { const { id, token } = user; @@ -154,12 +154,11 @@ export function sendFileMessage( uploadQueue[uploadPath].then(async response => { if (response.respInfo.status >= 200 && response.respInfo.status < 400) { - // If response is all good... try { await db.write(async () => { await uploadRecord.destroyPermanently(); }); - resolve(response); + resolve(); } catch (e) { log(e); }