1 import type { PrivateKeyReference, SessionKey } from '@proton/crypto';
3 import type { ThumbnailType } from './media';
5 export interface UploadFileControls {
6 start: (progressCallbacks?: UploadFileProgressCallbacks) => Promise<void>;
12 export interface UploadFileProgressCallbacks {
13 onInit?: (mimeType: string, fileName: string) => void;
14 onProgress?: (bytes: number) => void;
15 onNetworkError?: (error: any) => void;
16 onFinalize?: () => void;
19 export interface UploadFolderControls {
20 start: () => Promise<{ folderId: string; folderName: string }>;
24 export interface UploadCallbacks {
25 initialize: (abortSignal: AbortSignal) => Promise<{
26 addressPrivateKey: PrivateKeyReference;
27 parentPrivateKey: PrivateKeyReference;
29 getVerificationData: (abortSignal: AbortSignal) => Promise<VerificationData>;
30 createFileRevision: (abortSignal: AbortSignal, mimeType: string, keys: FileKeys) => Promise<InitializedFileMeta>;
32 abortSignal: AbortSignal,
33 fileBlocks: FileRequestBlock[],
34 thumbnailBlocks?: ThumbnailRequestBlock[]
35 ) => Promise<{ fileLinks: Link[]; thumbnailLinks?: Link[] }>;
36 finalize: (signature: string, signatureAddress: string, xattr: string, photo?: PhotoUpload) => Promise<void>;
37 onError?: (error: Error) => void;
38 notifyVerificationError: (retryHelped: boolean) => void;
41 export type UploadFileList = (UploadFileItem | UploadFolderItem)[];
42 export type UploadFileItem = { path: string[]; file: File };
43 export type UploadFolderItem = { path: string[]; folder: string; modificationTime?: Date };
45 export type FileKeys = {
47 nodePassphrase: string;
48 nodePassphraseSignature: string;
49 contentKeyPacket: string;
50 contentKeyPacketSignature: string;
51 privateKey: PrivateKeyReference;
52 sessionKey: SessionKey;
55 type InitializedFileMeta = {
57 privateKey: PrivateKeyReference;
58 sessionKey: SessionKey;
59 parentHashKey: Uint8Array;
61 privateKey: PrivateKeyReference;
66 export type EncryptedBlock = {
69 encryptedData: Uint8Array;
72 verificationToken: Uint8Array;
74 // Thumbnails specific properties
75 thumbnailType?: never;
78 export type ThumbnailEncryptedBlock = {
81 encryptedData: Uint8Array;
84 // Thumbnails specific properties
85 thumbnailType: ThumbnailType;
88 export type FileRequestBlock = {
93 verificationToken: Uint8Array;
96 export type ThumbnailRequestBlock = {
103 export type VerificationData = {
104 verificationCode: Uint8Array;
105 verifierSessionKey: SessionKey;
114 export type PhotoUpload = {
115 encryptedExif?: string;
117 contentHash?: string;
120 export enum TransferConflictStrategy {