Skip to content

Commit f073724

Browse files
Merge pull request #8 from DevExpress-Examples/minor-fixes
Update all projects
2 parents 59335aa + 2945b7c commit f073724

22 files changed

+702
-388
lines changed

ASP.NET Core/Views/Home/Index.cshtml

Lines changed: 99 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -3,85 +3,127 @@
33
<h2>Home</h2>
44

55
@(Html.DevExtreme().FileManager()
6-
.ID("file-manager")
7-
.FileSystemProvider(provider => provider.Custom()
8-
.GetItems("getItems")
9-
.CreateDirectory("createDirectory")
10-
.RenameItem("renameItem")
11-
.DeleteItem("deleteItem")
12-
.CopyItem("copyItem")
13-
.MoveItem("moveItem")
14-
.UploadFileChunk("uploadFileChunk")
15-
.DownloadItems("downloadItems")
16-
)
17-
.Permissions(permissions =>
18-
{
19-
permissions.Download(true);
20-
permissions.Create(true);
21-
permissions.Copy(true);
22-
permissions.Move(true);
23-
permissions.Delete(true);
24-
permissions.Rename(true);
25-
permissions.Upload(true);
26-
})
27-
.Upload(upload => upload.ChunkSize(600000))
28-
.AllowedFileExtensions(new string[0])
29-
)
6+
.ID("file-manager")
7+
.FileSystemProvider(provider => provider.Custom()
8+
.GetItems("getItems")
9+
.CreateDirectory("createDirectory")
10+
.RenameItem("renameItem")
11+
.DeleteItem("deleteItem")
12+
.CopyItem("copyItem")
13+
.MoveItem("moveItem")
14+
.UploadFileChunk("uploadFileChunk")
15+
.DownloadItems("downloadItems")
16+
.AbortFileUpload("abortFileUpload")
17+
)
18+
.Permissions(permissions =>
19+
{
20+
permissions.Download(true);
21+
permissions.Create(true);
22+
permissions.Copy(true);
23+
permissions.Move(true);
24+
permissions.Delete(true);
25+
permissions.Rename(true);
26+
permissions.Upload(true);
27+
})
28+
.Upload(upload => upload.ChunkSize(5242880))
29+
.AllowedFileExtensions(new string[0])
30+
)
31+
3032
<div id="request-panel"></div>
3133
<script src="~/js/amazon.gateway.js"></script>
3234
<script src="~/js/amazon.filesystem.js"></script>
3335
<script type="text/javascript">
3436
35-
baseUrl = `https://localhost:52366/api/AmazonS3`;
36-
amazon = new AmazonFileSystem(baseUrl, onRequestExecuted);
37+
baseUrl = `https://localhost:52366/api/AmazonS3`;
38+
amazon = new AmazonFileSystem(baseUrl, onRequestExecuted);
39+
40+
async function getItems(item) {
41+
try {
42+
return amazon.getItems(item.key);
43+
} catch (error) {
44+
throw new DevExpress.fileManagement.FileSystemError(32767, item, error.message);
45+
}
46+
}
3747
38-
function getItems(item) {
39-
return amazon.getItems(item.key);
48+
async function createDirectory(parentDirectory, name) {
49+
try {
50+
await amazon.createDirectory(parentDirectory.key, name);
51+
} catch (error) {
52+
throw new DevExpress.fileManagement.FileSystemError(32767, item, error.message);
53+
}
4054
}
4155
42-
function createDirectory(parentDirectory, name) {
43-
return amazon.createDirectory(parentDirectory.key, name);
56+
async function renameItem(item, name) {
57+
try {
58+
await amazon.renameItem(item.key, item.parentPath, name);
59+
} catch (error) {
60+
throw new DevExpress.fileManagement.FileSystemError(32767, item, error.message);
61+
}
4462
}
4563
46-
function renameItem(item, name) {
47-
return amazon.renameItem(item.key, item.parentPath, name);
64+
async function deleteItem(item) {
65+
try {
66+
await amazon.deleteItem(item.key);
67+
} catch (error) {
68+
throw new DevExpress.fileManagement.FileSystemError(32767, item, error.message);
69+
}
4870
}
4971
50-
function deleteItem(item) {
51-
return amazon.deleteItem(item.key);
72+
async function copyItem(item, destinationDirectory) {
73+
try {
74+
await amazon.copyItem(item, destinationDirectory);
75+
} catch (error) {
76+
throw new DevExpress.fileManagement.FileSystemError(32767, item, error.message);
77+
}
5278
}
5379
54-
function copyItem(item, destinationDirectory) {
55-
return amazon.copyItem(item, destinationDirectory);
80+
async function moveItem(item, destinationDirectory) {
81+
try {
82+
await amazon.moveItem(item, destinationDirectory);
83+
} catch (error) {
84+
throw new DevExpress.fileManagement.FileSystemError(32767, item, error.message);
85+
}
5686
}
5787
58-
function moveItem(item, destinationDirectory) {
59-
return amazon.moveItem(item, destinationDirectory);
88+
async function abortFileUpload(fileData, uploadInfo, destinationDirectory) {
89+
try {
90+
await amazon.abortFileUpload(fileData, uploadInfo, destinationDirectory);
91+
} catch (error) {
92+
throw new Error(error.message);
93+
}
6094
}
6195
6296
async function uploadFileChunk(fileData, uploadInfo, destinationDirectory) {
63-
await amazon.uploadFileChunk(fileData, uploadInfo, destinationDirectory);
97+
try {
98+
await amazon.uploadFileChunk(fileData, uploadInfo, destinationDirectory);
99+
} catch (error) {
100+
throw new Error(error.message);
101+
}
64102
}
65103
66-
function downloadItems(items) {
67-
return amazon.downloadItems(items);
104+
async function downloadItems(items) {
105+
try {
106+
await amazon.downloadItems(items);
107+
} catch (error) {
108+
throw new Error(error.message);
109+
}
68110
}
69111
70-
function onRequestExecuted(e) {
71-
$("<div>").addClass("request-info").append(
72-
createParameterInfoDiv("Method:", e.method),
73-
createParameterInfoDiv("Url path:", e.urlPath),
74-
createParameterInfoDiv("Query string:", e.queryString),
75-
$("<br>")
76-
)
77-
.prependTo("#request-panel");
78-
}
79-
80-
function createParameterInfoDiv(name, value) {
81-
return $("<div>").addClass("parameter-info").append(
82-
$("<div>").addClass("parameter-name").text(name),
83-
$("<div>").addClass("parameter-value dx-theme-accent-as-text-color").text(value).attr("title", value)
84-
);
85-
}
112+
function onRequestExecuted(e) {
113+
$("<div>").addClass("request-info").append(
114+
createParameterInfoDiv("Method:", e.method),
115+
createParameterInfoDiv("Url path:", e.urlPath),
116+
createParameterInfoDiv("Query string:", e.queryString),
117+
$("<br>")
118+
)
119+
.prependTo("#request-panel");
120+
}
121+
122+
function createParameterInfoDiv(name, value) {
123+
return $("<div>").addClass("parameter-info").append(
124+
$("<div>").addClass("parameter-name").text(name),
125+
$("<div>").addClass("parameter-value dx-theme-accent-as-text-color").text(value).attr("title", value)
126+
);
127+
}
86128
87129
</script>

ASP.NET Core/wwwroot/js/amazon.filesystem.js

Lines changed: 31 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -5,70 +5,52 @@ class AmazonFileSystem {
55
this.gateway = new AmazonGateway(baseUrl, onRequestExecuted);
66
}
77

8-
async getItems(path) {
9-
try {
10-
return await this.gateway.getItems(path);
11-
} catch (error) {
12-
throw new DevExpress.fileManagement.FileSystemError(32767, path, error.message);
13-
}
8+
getItems(path) {
9+
return this.gateway.getItems(path);
1410
}
1511

16-
async createDirectory(key, name) {
17-
try {
18-
return await this.gateway.createDirectory(key, name);
19-
} catch (error) {
20-
throw new DevExpress.fileManagement.FileSystemError(32767, name, error.message);
21-
}
12+
createDirectory(key, name) {
13+
return this.gateway.createDirectory(key, name);
2214
}
2315

24-
async renameItem(key, parentPath, name) {
25-
try {
26-
return await this.gateway.renameItem(key, `${parentPath}/`, name);
27-
} catch (error) {
28-
throw new DevExpress.fileManagement.FileSystemError(32767, key, error.message);
29-
}
16+
renameItem(key, parentPath, name) {
17+
return this.gateway.renameItem(key, `${parentPath}/`, name);
3018
}
3119

32-
async deleteItem(key) {
33-
try {
34-
return await this.gateway.deleteItem(key);
35-
} catch (error) {
36-
throw new DevExpress.fileManagement.FileSystemError(32767, key, error.message);
37-
}
20+
deleteItem(key) {
21+
return this.gateway.deleteItem(key);
3822
}
3923

40-
async copyItem(item, destinationDir) {
41-
try {
42-
return await this.gateway.copyItem(item.key, `${destinationDir.key}${item.name}`);
43-
} catch (error) {
44-
throw new DevExpress.fileManagement.FileSystemError(32767, item.key, error.message);
45-
}
24+
copyItem(item, destinationDir) {
25+
return this.gateway.copyItem(item.key, `${destinationDir.key}${item.name}`);
4626
}
4727

48-
async moveItem(item, destinationDir) {
49-
try {
50-
return await this.gateway.moveItem(item.key, `${destinationDir.key}${item.name}`);
51-
} catch (error) {
52-
throw new DevExpress.fileManagement.FileSystemError(32767, item.key, error.message);
53-
}
28+
moveItem(item, destinationDir) {
29+
return this.gateway.moveItem(item.key, `${destinationDir.key}${item.name}`);
5430
}
5531

56-
async uploadFileChunk(fileData, uploadInfo, destinationDirectory) {
57-
try {
58-
if (uploadInfo.chunkIndex === 0) {
59-
await this.gateway.initUpload(fileData, destinationDirectory);
60-
}
32+
async abortFileUpload(fileData, uploadInfo, destinationDirectory) {
33+
await this.gateway.abortFileUpload(fileData, uploadInfo, destinationDirectory);
34+
}
6135

62-
await this.gateway.uploadPart(fileData, uploadInfo, destinationDirectory);
36+
async uploadFileChunk(fileData, uploadInfo, destinationDirectory) {
37+
if (uploadInfo.chunkIndex === 0) {
38+
await this.gateway.initUpload(fileData, destinationDirectory);
39+
}
40+
// upload part even if a chunk is first or last
41+
await this.gateway.uploadPart(fileData, uploadInfo, destinationDirectory);
6342

64-
if (uploadInfo.chunkCount === uploadInfo.chunkIndex + 1) {
65-
await this.gateway.completeUpload(fileData, uploadInfo, destinationDirectory);
66-
}
67-
} catch (error) {
68-
throw new DevExpress.fileManagement.FileSystemError(32767, fileData.name, error.message);
43+
if (uploadInfo.chunkCount === uploadInfo.chunkIndex + 1) {
44+
await this.gateway.completeUpload(fileData, uploadInfo, destinationDirectory);
6945
}
7046
}
7147

48+
/* eslint-disable-next-line spellcheck/spell-checker */
49+
async getPresignedDownloadUrl(fileName) {
50+
/* eslint-disable-next-line spellcheck/spell-checker */
51+
return this.gateway.getPresignedDownloadUrl(fileName);
52+
}
53+
7254
getFileNameFromKey(key) {
7355
const index = key.lastIndexOf('/');
7456
if (index === -1) {
@@ -80,11 +62,7 @@ class AmazonFileSystem {
8062
async downloadItems(items) {
8163
const keys = items.map((x) => x.key);
8264
const fileName = keys.length > 1 ? 'archive.zip' : this.getFileNameFromKey(keys[0]);
83-
try {
84-
const blob = await this.gateway.downloadItems(keys);
85-
saveAs(new Blob([blob], { type: 'application/octet-stream' }), fileName);
86-
} catch (error) {
87-
throw new DevExpress.fileManagement.FileSystemError(32767, fileName, error.message);
88-
}
65+
const blob = await this.gateway.downloadItems(keys);
66+
saveAs(new Blob([blob], { type: 'application/octet-stream' }), fileName);
8967
}
9068
}

0 commit comments

Comments
 (0)