Merge branch 'feat/inda-383-daily-stat' into 'main'
[ProtonMail-WebClient.git] / applications / drive / src / app / components / TransferManager / transfer.ts
blob36fd157e427c4e20d0a5a52ade57b0604ad18167
1 /* eslint-disable max-classes-per-file */
3 export enum TransferState {
4     Initializing = 'initializing',
5     Pending = 'pending',
6     Conflict = 'conflict',
7     SignatureIssue = 'signatureIssue',
8     ScanIssue = 'scanIssue',
9     Progress = 'progress',
10     Finalizing = 'finalizing',
11     Done = 'done',
12     Skipped = 'skipped',
13     Canceled = 'canceled',
14     Error = 'error',
15     NetworkError = 'networkError',
16     Paused = 'paused',
19 export interface TransferProgresses {
20     [id: string]: number;
23 export interface TransferMeta {
24     filename: string;
25     mimeType: string;
26     size?: number;
29 export interface TransferSummary {
30     size: number;
31     progress: number;
34 export class TransferCancel extends Error {
35     constructor(options: { id: string } | { message: string }) {
36         super('id' in options ? `Transfer ${options.id} canceled` : options.message);
37         this.name = 'TransferCancel';
38     }
40 export class TransferSkipped extends Error {
41     constructor(options: { id: string } | { message: string }) {
42         super('id' in options ? `Transfer ${options.id} skipped` : options.message);
43         this.name = 'TransferSkipped';
44     }
47 export class TransferConflict extends Error {
48     constructor(options: { id: string } | { message: string }) {
49         super('id' in options ? `Transfer ${options.id} is conflicting` : options.message);
50         this.name = 'TransferConflict';
51     }
54 export interface Upload {
55     id: string;
56     meta: TransferMeta;
57     state: TransferState;
58     startDate: Date;
59     error?: Error;
61     files?: Upload[];
62     folders?: Upload[];
65 export interface Download {
66     id: string;
67     meta: TransferMeta;
68     state: TransferState;
69     startDate: Date;
70     error?: Error;
71     scanIssueError?: Error;
74 export type Transfer = Upload | Download;
76 export interface TransferHistoryStats {
77     active: boolean;
78     progress: number;
79     speed: number;
82 export interface TransfersHistoryStats {
83     timestamp: Date;
84     stats: { [id: string]: TransferHistoryStats };
87 export interface TransferStats {
88     progress: number;
89     averageSpeed: number;
92 export interface TransfersStats {
93     [id: string]: TransferStats;
96 export enum TransferType {
97     Download = 'download',
98     Upload = 'upload',
101 export enum TransferGroup {
102     ACTIVE,
103     DONE,
104     QUEUED,
105     FAILURE,
108 export const STATE_TO_GROUP_MAP = {
109     [TransferState.Progress]: TransferGroup.ACTIVE,
110     [TransferState.Finalizing]: TransferGroup.ACTIVE,
111     [TransferState.Paused]: TransferGroup.ACTIVE,
112     [TransferState.SignatureIssue]: TransferGroup.ACTIVE,
113     [TransferState.ScanIssue]: TransferGroup.ACTIVE,
114     [TransferState.Skipped]: TransferGroup.FAILURE,
115     [TransferState.Canceled]: TransferGroup.FAILURE,
116     [TransferState.NetworkError]: TransferGroup.FAILURE,
117     [TransferState.Done]: TransferGroup.DONE,
118     [TransferState.Error]: TransferGroup.FAILURE,
119     [TransferState.Initializing]: TransferGroup.QUEUED,
120     [TransferState.Conflict]: TransferGroup.QUEUED,
121     [TransferState.Pending]: TransferGroup.QUEUED,