Skip to content

Commit

Permalink
Allow downloading files
Browse files Browse the repository at this point in the history
  • Loading branch information
datkat21 committed Jan 12, 2024
1 parent ff1b5c7 commit 8f41a0c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions assets/icons.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions pkgs/apps/FileManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,29 @@ export default {
html: L.icons.import,
title: "Import file from your system",
},
{
onclick: async (_) => {
if (!selectedItem) return;
let i = await vfs.whatIs(selectedItem);
if (i === "dir")
return Root.Modal.alert("Cannot download folders at the moment.");
let text = await vfs.readFile(selectedItem);

// boilerplate download code
var element = document.createElement("a");
element.setAttribute(
"href",
"data:text/plain;charset=utf-8," + encodeURIComponent(text)
);
element.setAttribute("download", selectedItem.split('/').pop());
element.style.display = "none";
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
},
html: L.icons.download,
title: "Download File",
},
{
onclick: async (_) => {
if (!selectedItem) return;
Expand Down

0 comments on commit 8f41a0c

Please sign in to comment.