Skip to content

Update all projects #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
156 changes: 99 additions & 57 deletions ASP.NET Core/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,85 +3,127 @@
<h2>Home</h2>

@(Html.DevExtreme().FileManager()
.ID("file-manager")
.FileSystemProvider(provider => provider.Custom()
.GetItems("getItems")
.CreateDirectory("createDirectory")
.RenameItem("renameItem")
.DeleteItem("deleteItem")
.CopyItem("copyItem")
.MoveItem("moveItem")
.UploadFileChunk("uploadFileChunk")
.DownloadItems("downloadItems")
)
.Permissions(permissions =>
{
permissions.Download(true);
permissions.Create(true);
permissions.Copy(true);
permissions.Move(true);
permissions.Delete(true);
permissions.Rename(true);
permissions.Upload(true);
})
.Upload(upload => upload.ChunkSize(600000))
.AllowedFileExtensions(new string[0])
)
.ID("file-manager")
.FileSystemProvider(provider => provider.Custom()
.GetItems("getItems")
.CreateDirectory("createDirectory")
.RenameItem("renameItem")
.DeleteItem("deleteItem")
.CopyItem("copyItem")
.MoveItem("moveItem")
.UploadFileChunk("uploadFileChunk")
.DownloadItems("downloadItems")
.AbortFileUpload("abortFileUpload")
)
.Permissions(permissions =>
{
permissions.Download(true);
permissions.Create(true);
permissions.Copy(true);
permissions.Move(true);
permissions.Delete(true);
permissions.Rename(true);
permissions.Upload(true);
})
.Upload(upload => upload.ChunkSize(5242880))
.AllowedFileExtensions(new string[0])
)

<div id="request-panel"></div>
<script src="~/js/amazon.gateway.js"></script>
<script src="~/js/amazon.filesystem.js"></script>
<script type="text/javascript">

baseUrl = `https://localhost:52366/api/AmazonS3`;
amazon = new AmazonFileSystem(baseUrl, onRequestExecuted);
baseUrl = `https://localhost:52366/api/AmazonS3`;
amazon = new AmazonFileSystem(baseUrl, onRequestExecuted);

async function getItems(item) {
try {
return amazon.getItems(item.key);
} catch (error) {
throw new DevExpress.fileManagement.FileSystemError(32767, item, error.message);
}
}

function getItems(item) {
return amazon.getItems(item.key);
async function createDirectory(parentDirectory, name) {
try {
await amazon.createDirectory(parentDirectory.key, name);
} catch (error) {
throw new DevExpress.fileManagement.FileSystemError(32767, item, error.message);
}
}

function createDirectory(parentDirectory, name) {
return amazon.createDirectory(parentDirectory.key, name);
async function renameItem(item, name) {
try {
await amazon.renameItem(item.key, item.parentPath, name);
} catch (error) {
throw new DevExpress.fileManagement.FileSystemError(32767, item, error.message);
}
}

function renameItem(item, name) {
return amazon.renameItem(item.key, item.parentPath, name);
async function deleteItem(item) {
try {
await amazon.deleteItem(item.key);
} catch (error) {
throw new DevExpress.fileManagement.FileSystemError(32767, item, error.message);
}
}

function deleteItem(item) {
return amazon.deleteItem(item.key);
async function copyItem(item, destinationDirectory) {
try {
await amazon.copyItem(item, destinationDirectory);
} catch (error) {
throw new DevExpress.fileManagement.FileSystemError(32767, item, error.message);
}
}

function copyItem(item, destinationDirectory) {
return amazon.copyItem(item, destinationDirectory);
async function moveItem(item, destinationDirectory) {
try {
await amazon.moveItem(item, destinationDirectory);
} catch (error) {
throw new DevExpress.fileManagement.FileSystemError(32767, item, error.message);
}
}

function moveItem(item, destinationDirectory) {
return amazon.moveItem(item, destinationDirectory);
async function abortFileUpload(fileData, uploadInfo, destinationDirectory) {
try {
await amazon.abortFileUpload(fileData, uploadInfo, destinationDirectory);
} catch (error) {
throw new Error(error.message);
}
}

async function uploadFileChunk(fileData, uploadInfo, destinationDirectory) {
await amazon.uploadFileChunk(fileData, uploadInfo, destinationDirectory);
try {
await amazon.uploadFileChunk(fileData, uploadInfo, destinationDirectory);
} catch (error) {
throw new Error(error.message);
}
}

function downloadItems(items) {
return amazon.downloadItems(items);
async function downloadItems(items) {
try {
await amazon.downloadItems(items);
} catch (error) {
throw new Error(error.message);
}
}

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)
);
}
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)
);
}

</script>
84 changes: 31 additions & 53 deletions ASP.NET Core/wwwroot/js/amazon.filesystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,70 +5,52 @@ class AmazonFileSystem {
this.gateway = new AmazonGateway(baseUrl, onRequestExecuted);
}

async getItems(path) {
try {
return await this.gateway.getItems(path);
} catch (error) {
throw new DevExpress.fileManagement.FileSystemError(32767, path, error.message);
}
getItems(path) {
return this.gateway.getItems(path);
}

async createDirectory(key, name) {
try {
return await this.gateway.createDirectory(key, name);
} catch (error) {
throw new DevExpress.fileManagement.FileSystemError(32767, name, error.message);
}
createDirectory(key, name) {
return this.gateway.createDirectory(key, name);
}

async renameItem(key, parentPath, name) {
try {
return await this.gateway.renameItem(key, `${parentPath}/`, name);
} catch (error) {
throw new DevExpress.fileManagement.FileSystemError(32767, key, error.message);
}
renameItem(key, parentPath, name) {
return this.gateway.renameItem(key, `${parentPath}/`, name);
}

async deleteItem(key) {
try {
return await this.gateway.deleteItem(key);
} catch (error) {
throw new DevExpress.fileManagement.FileSystemError(32767, key, error.message);
}
deleteItem(key) {
return this.gateway.deleteItem(key);
}

async copyItem(item, destinationDir) {
try {
return await this.gateway.copyItem(item.key, `${destinationDir.key}${item.name}`);
} catch (error) {
throw new DevExpress.fileManagement.FileSystemError(32767, item.key, error.message);
}
copyItem(item, destinationDir) {
return this.gateway.copyItem(item.key, `${destinationDir.key}${item.name}`);
}

async moveItem(item, destinationDir) {
try {
return await this.gateway.moveItem(item.key, `${destinationDir.key}${item.name}`);
} catch (error) {
throw new DevExpress.fileManagement.FileSystemError(32767, item.key, error.message);
}
moveItem(item, destinationDir) {
return this.gateway.moveItem(item.key, `${destinationDir.key}${item.name}`);
}

async uploadFileChunk(fileData, uploadInfo, destinationDirectory) {
try {
if (uploadInfo.chunkIndex === 0) {
await this.gateway.initUpload(fileData, destinationDirectory);
}
async abortFileUpload(fileData, uploadInfo, destinationDirectory) {
await this.gateway.abortFileUpload(fileData, uploadInfo, destinationDirectory);
}

await this.gateway.uploadPart(fileData, uploadInfo, destinationDirectory);
async uploadFileChunk(fileData, uploadInfo, destinationDirectory) {
if (uploadInfo.chunkIndex === 0) {
await this.gateway.initUpload(fileData, destinationDirectory);
}
// upload part even if a chunk is first or last
await this.gateway.uploadPart(fileData, uploadInfo, destinationDirectory);

if (uploadInfo.chunkCount === uploadInfo.chunkIndex + 1) {
await this.gateway.completeUpload(fileData, uploadInfo, destinationDirectory);
}
} catch (error) {
throw new DevExpress.fileManagement.FileSystemError(32767, fileData.name, error.message);
if (uploadInfo.chunkCount === uploadInfo.chunkIndex + 1) {
await this.gateway.completeUpload(fileData, uploadInfo, destinationDirectory);
}
}

/* eslint-disable-next-line spellcheck/spell-checker */
async getPresignedDownloadUrl(fileName) {
/* eslint-disable-next-line spellcheck/spell-checker */
return this.gateway.getPresignedDownloadUrl(fileName);
}

getFileNameFromKey(key) {
const index = key.lastIndexOf('/');
if (index === -1) {
Expand All @@ -80,11 +62,7 @@ class AmazonFileSystem {
async downloadItems(items) {
const keys = items.map((x) => x.key);
const fileName = keys.length > 1 ? 'archive.zip' : this.getFileNameFromKey(keys[0]);
try {
const blob = await this.gateway.downloadItems(keys);
saveAs(new Blob([blob], { type: 'application/octet-stream' }), fileName);
} catch (error) {
throw new DevExpress.fileManagement.FileSystemError(32767, fileName, error.message);
}
const blob = await this.gateway.downloadItems(keys);
saveAs(new Blob([blob], { type: 'application/octet-stream' }), fileName);
}
}
Loading
Loading