aboutsummaryrefslogtreecommitdiffstats
path: root/loggedin.js
diff options
context:
space:
mode:
authorAlex Vitkov <alexvitkov98@gmail.com>2021-02-14 09:40:10 +0200
committerAlex Vitkov <alexvitkov98@gmail.com>2021-02-14 09:40:10 +0200
commite55c72279c25617f441049ab0be6fd6843eecdd5 (patch)
tree6928c3748d0bb648b20653684b52324e8ad1a439 /loggedin.js
parent3005c7774d4f32dc857a9b10c4e621f4df2019c4 (diff)
downloadfileup-e55c72279c25617f441049ab0be6fd6843eecdd5.tar.gz
Download link
Diffstat (limited to 'loggedin.js')
-rw-r--r--loggedin.js67
1 files changed, 63 insertions, 4 deletions
diff --git a/loggedin.js b/loggedin.js
index 451b926..d54bdb6 100644
--- a/loggedin.js
+++ b/loggedin.js
@@ -145,6 +145,28 @@ function update_path_visuals() {
}
}
+function read_file_contents(text, cb, folder, filename) {
+ var data = new FormData();
+ data.append('folder', folder);
+ data.append('filename', filename);
+
+ let xhr = new XMLHttpRequest();
+ xhr.open('POST', '/php/readfile.php', true);
+
+ if (text) {
+ xhr.onload = function () {
+ cb(e.responseText);
+ };
+ } else {
+ xhr.responseType = 'arraybuffer';
+ xhr.onload = function () {
+ cb(xhr.response);
+ };
+ }
+
+ xhr.send(data);
+}
+
function openfile_nondir() {
var mimetype = "text/plain";
@@ -597,6 +619,35 @@ function make_share_window(folder, filename) {
return wnd;
}
+function download_file(in_file, filename) {
+
+ if (in_file) {
+ var folder = get_path(focus.pwd.length - 1);
+ filename = focus.pwd[focus.pwd.length - 1];
+ } else {
+ var folder = get_path();
+ }
+
+ read_file_contents(false, (x) => {
+ var blob = new Blob([new Uint8Array(x, 0, x.length)]);
+ var url = URL.createObjectURL(blob);
+ var a = document.createElement('a');
+ a.href = url;
+ a.download = "filename";
+ document.body.appendChild(a);
+ a.click();
+ setTimeout(() => {
+ document.body.removeChild(a);
+ URL.revokeObjectURL(url);
+ });
+ }, folder, filename);
+
+ return;
+}
+
+
+
+
function delete_window() {
var index = windows.indexOf(focus);
if (index >= 0) {
@@ -631,19 +682,19 @@ function make_window(pwd) {
}
{
- wnd.filecontentsroot = mk(wnd.visuals, 'div');
+ wnd.filecontentsroot = mk(wnd.visuals, 'div', 'filecontentsroot');
var h3 = mk(wnd.filecontentsroot, 'h3');
var download_btn = mk(h3, 'button');
download_btn.innerText = "Download";
- download_btn.onclick = () => { download_file(); }
+ download_btn.onclick = () => { download_file(true); }
mk(h3, 'div', 'separator');
var download_btn = mk(h3, 'button');
download_btn.innerText = "Share";
download_btn.onclick = () => { share(true); }
-
+
mk(h3, 'div', 'separator');
wnd.filecontents = mk(wnd.filecontentsroot, 'div', 'filecontents');
@@ -687,7 +738,7 @@ function add_file_visuals(fileview) {
focus.pwd.push(fileview.filename);
openfile(fileview.is_directory);
}],
- ['Open in New Window', () => {alert('not implemented')}],
+ // ['Open in New Window', () => {alert('not implemented')}],
];
if (is_in_trash) {
@@ -696,6 +747,14 @@ function add_file_visuals(fileview) {
} else if (!is_trash) {
context_list.push(
['Rename', () => { rename_file(fileview.filename); }],
+ );
+ if (!fileview.is_directory) {
+ context_list.push(
+ ['Share', () => { share(false, fileview.filename); }],
+ ['Download', () => { download_file(false, fileview.filename); }],
+ );
+ }
+ context_list.push(
['Share', () => { share(false, fileview.filename); }],
['Delete', () => { move_to_trash(fileview.filename); }]
);