-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.component.ts
87 lines (68 loc) · 2.64 KB
/
app.component.ts
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import { Component } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { lastValueFrom } from 'rxjs';
import UploadInfo from 'devextreme/file_management/upload_info';
import { ValueChangedEvent, UploadedEvent } from 'devextreme/ui/file_uploader';
import { AmazonGateway } from './services/amazon.gateway';
import { AmazonFileSystem } from './services/amazon.filesystem';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
})
export class AppComponent {
requests: any[];
wrapperClassName: string;
loadPanelVisible: boolean;
downloadFileName: string;
downloadUrl: string;
gateway: AmazonGateway;
amazon: AmazonFileSystem;
downloadPanelVisible: boolean;
constructor(http: HttpClient) {
const endpointUrl = 'https://localhost:52366/api/AmazonS3';
this.gateway = new AmazonGateway(endpointUrl, this.onRequestExecuted.bind(this));
this.amazon = new AmazonFileSystem(this.gateway);
this.requests = [];
this.wrapperClassName = '';
this.loadPanelVisible = true;
this.downloadFileName = '';
this.downloadUrl = '';
this.downloadPanelVisible = false;
this.checkAmazonStatus(http);
this.uploadChunk = this.uploadChunk.bind(this);
this.abortUpload = this.abortUpload.bind(this);
this.onUploaded = this.onUploaded.bind(this);
this.onValueChanged = this.onValueChanged.bind(this);
}
async uploadChunk(file: File, uploadInfo: UploadInfo): Promise<any> {
return this.amazon.uploadFileChunk(file, uploadInfo, undefined);
}
async abortUpload(file: File, uploadInfo: UploadInfo): Promise<any> {
return this.amazon.abortFileUpload(file, uploadInfo, undefined);
}
async onUploaded(e: UploadedEvent): Promise<any> {
const url = await this.amazon.getPresignedDownloadUrl(e.file.name);
this.downloadFileName = e.file.name;
this.downloadUrl = url;
this.downloadPanelVisible = true;
}
onValueChanged(e: ValueChangedEvent): void {
this.downloadPanelVisible = false;
this.downloadFileName = '';
this.downloadUrl = '';
}
onRequestExecuted({ method, urlPath, queryString }: { method: string; urlPath: string; queryString: string }): void {
const request = { method, urlPath, queryString };
this.requests.unshift(request);
}
checkAmazonStatus(http: HttpClient): void {
lastValueFrom(http.get<{ active: boolean }>('https://localhost:52366/api/AmazonS3/getItems'))
.then((result) => {
result.active = true;
this.wrapperClassName = result.active ? 'show-widget' : 'show-message';
this.loadPanelVisible = false;
})
.catch(() => { });
}
}