-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
83 lines (73 loc) · 2.24 KB
/
index.js
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
$(() => {
const loadPanel = $('#load-panel').dxLoadPanel({
position: { of: '#file-uploader' },
visible: true,
}).dxLoadPanel('instance');
$.ajax({
url: 'https://localhost:52366/api/AmazonS3/getItems',
success(result) {
result.active = true;
const className = result.active ? 'show-widget' : 'show-message';
$('#wrapper').addClass(className);
loadPanel.hide();
},
});
baseUrl = 'https://localhost:52366/api/AmazonS3';
amazon = new AmazonFileSystem(baseUrl, onRequestExecuted);
$('#file-uploader').dxFileUploader({
chunkSize: 5242880,
abortUpload,
uploadChunk,
onValueChanged,
onUploaded,
});
});
async function onUploaded(e) {
/* eslint-disable-next-line spellcheck/spell-checker */
const url = await amazon.getPresignedDownloadUrl(e.file.name);
/* eslint-disable-next-line spellcheck/spell-checker */
showPresignedUrl(url, e.file.name);
}
function onValueChanged(e) {
/* eslint-disable-next-line spellcheck/spell-checker */
hidePresignedUrl();
}
async function abortUpload(file, uploadInfo) {
return amazon.abortUpload(file, uploadInfo);
}
async function uploadChunk(file, uploadInfo) {
return amazon.uploadFileChunk(file, uploadInfo);
}
/* eslint-disable-next-line spellcheck/spell-checker */
function showPresignedUrl(url, fileName) {
$('<div>')
.attr('id', 'url-div')
.append(
$('<span>').text('Download uploaded file: '),
$('<a>')
.attr('href', url)
.attr('target', '_blank')
.text(fileName),
)
.appendTo('#download-panel');
}
/* eslint-disable-next-line spellcheck/spell-checker */
function hidePresignedUrl() {
$('#url-div').remove();
}
function onRequestExecuted(e) {
$('<div>').addClass('request-info').append(
createParameterInfoDiv('Method:', e.method),
createParameterInfoDiv('Url path:', e.urlPath),
createParameterInfoDiv('Query string:', e.queryString),
$('<br>'),
)
.prependTo('#request-panel');
}
function createParameterInfoDiv(name, value) {
return $('<div>').addClass('parameter-info').append(
$('<div>').addClass('parameter-name').text(name),
$('<div>').addClass('parameter-value dx-theme-accent-as-text-color').text(value).attr('title', value),
);
}
const gateway = null;