fix types

This commit is contained in:
GleidsonDaniel 2024-04-30 08:36:50 -03:00
parent 99115b88b3
commit 0aae4dfd78
2 changed files with 9 additions and 10 deletions

View File

@ -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<EventTarget>) => any) | null) {
public catch(callback: ((this: XMLHttpRequest, ev: ProgressEvent<EventTarget>) => 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<void> {
this.xhr.abort();
return Promise.resolve();
}

View File

@ -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<Pick<IUser, 'id' | 'token'>>,
isForceTryAgain?: boolean
): Promise<any | void> {
): Promise<void> {
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);
}