keanu-weblite/src/models/attachment.ts

52 lines
1.3 KiB
TypeScript
Raw Normal View History

2025-06-09 09:44:37 +02:00
export class UploadPromise<Type> {
wrappedPromise: Promise<Type>;
aborted: boolean = false;
onAbort: (() => void) | undefined = undefined;
constructor(wrappedPromise: Promise<Type>) {
this.wrappedPromise = wrappedPromise;
}
abort() {
this.aborted = true;
if (this.onAbort) {
this.onAbort();
}
}
then(resolve: any, reject: any) {
this.wrappedPromise = this.wrappedPromise.then(resolve, reject);
return this;
}
catch(handler: any) {
this.wrappedPromise = this.wrappedPromise.catch(handler);
return this;
}
}
export type AttachmentSendStatus = "initial" | "sending" | "sent" | "canceled" | "failed";
export type AttachmentSendInfo = {
status: AttachmentSendStatus;
statusDate: number; //ms
mediaEventId: string | undefined;
progress: number;
promise: UploadPromise<string> | undefined;
randomRotation: number; // For UI effects
randomTranslationX: number; // For UI effects
randomTranslationY: number; // For UI effects
};
export type Attachment = {
status: "loading" | "loaded";
file: File;
dimensions?: { width: number; height: number };
scaledFile?: File;
scaledDimensions?: { width: number; height: number };
useScaled: boolean;
src?: string;
proof?: any;
sendInfo?: AttachmentSendInfo;
};