-
Notifications
You must be signed in to change notification settings - Fork 130
Expand file tree
/
Copy pathfolder_manager.ts
More file actions
38 lines (33 loc) · 1.14 KB
/
folder_manager.ts
File metadata and controls
38 lines (33 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import filebrowser from "@/libs/filebrowser";
export class FolderManager {
public downloadedBytes: number = 0;
public totalBytes: number = 0;
public startTime: number = 0;
public downloadSpeed: number = 0;
public inProgress: boolean = false;
async downloadFolder(
logs: string,
): Promise<void> {
const folder = await filebrowser.fetchFolder(logs);
this.inProgress = true;
await filebrowser.downloadFolder(folder, (event) => {
if (this.startTime === 0) this.startTime = Date.now()
const current_time = Date.now()
const elapsed = (current_time - this.startTime) / 1000
this.startTime = current_time
this.downloadedBytes = event.bytes
this.totalBytes = event.loaded
this.downloadSpeed = event.bytes / elapsed
})
.finally(() => {
this.resetDownloadVariables()
this.inProgress = false;
})
}
resetDownloadVariables(): void {
this.downloadedBytes = 0;
this.totalBytes = 0;
this.startTime = 0;
this.downloadSpeed = 0;
}
}