From d72db6897c4eb6638fc43240181218f124958578 Mon Sep 17 00:00:00 2001 From: Alex Vitkov Date: Sat, 13 Feb 2021 16:05:19 +0200 Subject: trash --- loggedin.js | 47 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/loggedin.js b/loggedin.js index 53aa7c7..de0f915 100644 --- a/loggedin.js +++ b/loggedin.js @@ -169,11 +169,18 @@ function move_to_trash(filename) { move_file("/trash", filename, path_combine(get_path(), filename)); } -function delete_file(filename) { - var file_full_path = path_combine(get_path(), filename); +function restore_from_trash(filename) { + var split = filename.split("/"); + var new_filename = split.pop(); + var new_directory = "/" + split.join("/"); + + move_file(new_directory, filename, new_filename); +} +function delete_file(filename) { var data = new FormData(); - data.append('path', file_full_path); + data.append('folder', get_path()); + data.append('filename', filename); var xhr = new XMLHttpRequest(); xhr.open('POST', '/php/delete.php', true); @@ -399,6 +406,8 @@ function make_window(pwd) { function add_file_visuals(fileview) { + var is_in_trash = focus.pwd.length == 1 && focus.pwd[0] == "trash"; + var visuals = document.createElement('div'); fileview.visuals = visuals; @@ -421,16 +430,27 @@ function add_file_visuals(fileview) { visuals.oncontextmenu = (e) => { if (!dragging) { - context(e, [ + + var context_list = [ ['Open', () => { focus.pwd.push(fileview.filename); openfile(fileview.is_directory); - }], + }], ['Open in New Window', () => {alert('not implemented')}], - ['Rename', () => { rename_file(fileview.filename); }], - ['Share', () => {alert('not implemented')}], - ['Delete', () => { move_to_trash(fileview.filename); }], - ]); + ]; + + if (is_in_trash) { + context_list.push(['Restore', () => { restore_from_trash(fileview.filename); }]); + context_list.push(['Delete forever', () => { delete_file(fileview.filename); }]); + } else { + context_list.push( + ['Rename', () => { rename_file(fileview.filename); }], + ['Share', () => {alert('not implemented')}], + ['Delete', () => { move_to_trash(fileview.filename); }] + ); + } + + context(e, context_list); } e.preventDefault(); e.stopPropagation(); @@ -451,10 +471,13 @@ function add_file_visuals(fileview) { visuals.classList.add('file'); filename.classList.add('filename'); - filename.innerText = fileview.filename; - if (fileview.mimetype == "pending") - visuals.classList.add('pending'); + if (is_in_trash) { + var split = fileview.filename.split("/"); + filename.innerText = split[split.length - 1]; + } else { + filename.innerText = fileview.filename; + } visuals.appendChild(img); visuals.appendChild(filename); -- cgit v1.2.3 From 4bd4895ea131541190a5154c5f0de0380ef38842 Mon Sep 17 00:00:00 2001 From: Alex Vitkov Date: Sat, 13 Feb 2021 16:09:07 +0200 Subject: can no longer drag around the fucking trashcan --- loggedin.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/loggedin.js b/loggedin.js index de0f915..8de7c2b 100644 --- a/loggedin.js +++ b/loggedin.js @@ -104,7 +104,7 @@ function openfile_nondir() { xhr.open('POST', '/php/readfile.php', true); - focus.filecontents.innerText = "Loading..."; + focus.filecontents.innerText = ""; focus.filecontents.style.display = 'block'; focus.foldercontents.style.display = 'none'; @@ -457,6 +457,10 @@ function add_file_visuals(fileview) { } visuals.ondragstart = (e) => { + if (focus.pwd.length == 0 && fileview.filename == "trash") { + e.preventDefault(); + return; + } begin_drag_fileview(e, fileview); e.preventDefault(); }; -- cgit v1.2.3 From a66f9b08e57ec10a484d6ca658ce52a7096870be Mon Sep 17 00:00:00 2001 From: Alex Vitkov Date: Sat, 13 Feb 2021 16:13:03 +0200 Subject: can no longer rename the fucking trashcan --- loggedin.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/loggedin.js b/loggedin.js index 8de7c2b..9a37c91 100644 --- a/loggedin.js +++ b/loggedin.js @@ -407,6 +407,7 @@ function make_window(pwd) { function add_file_visuals(fileview) { var is_in_trash = focus.pwd.length == 1 && focus.pwd[0] == "trash"; + var is_trash = focus.pwd.length == 0 && fileview.filename == "trash"; var visuals = document.createElement('div'); fileview.visuals = visuals; @@ -442,7 +443,7 @@ function add_file_visuals(fileview) { if (is_in_trash) { context_list.push(['Restore', () => { restore_from_trash(fileview.filename); }]); context_list.push(['Delete forever', () => { delete_file(fileview.filename); }]); - } else { + } else if (!is_trash) { context_list.push( ['Rename', () => { rename_file(fileview.filename); }], ['Share', () => {alert('not implemented')}], @@ -479,6 +480,8 @@ function add_file_visuals(fileview) { if (is_in_trash) { var split = fileview.filename.split("/"); filename.innerText = split[split.length - 1]; + } else if (is_trash) { + filename.innerText = "Trash"; } else { filename.innerText = fileview.filename; } -- cgit v1.2.3 From 1da51d081ffc4d54a6e31273826f6114ea9adf1d Mon Sep 17 00:00:00 2001 From: Alex Vitkov Date: Sat, 13 Feb 2021 16:25:21 +0200 Subject: icons --- loggedin.js | 6 ++++-- mimeicons/application-octet-stream.png | Bin 642 -> 520 bytes mimeicons/application-pdf.png | Bin 2510 -> 1852 bytes mimeicons/application-rss_xml.png | Bin 2072 -> 1612 bytes mimeicons/application-x-bittorrent.png | Bin 955 -> 791 bytes mimeicons/application-x-cd-image.png | Bin 3996 -> 2914 bytes mimeicons/application-x-executable.png | Bin 2621 -> 2307 bytes mimeicons/application-x-object.png | Bin 2913 -> 2189 bytes mimeicons/audio-x-generic.png | Bin 1205 -> 1095 bytes mimeicons/font-x-generic.png | Bin 2564 -> 2059 bytes mimeicons/image-x-generic.png | Bin 494 -> 409 bytes mimeicons/package-x-generic.png | Bin 539 -> 458 bytes mimeicons/text-html.png | Bin 3293 -> 2440 bytes mimeicons/text-vnd.trolltech.linguist.png | Bin 2815 -> 1995 bytes mimeicons/text-x-c.png | Bin 0 -> 2415 bytes mimeicons/text-x-changelog.png | Bin 1329 -> 1022 bytes mimeicons/text-x-chdr.png | Bin 2077 -> 1622 bytes mimeicons/text-x-cpp.png | Bin 2354 -> 1661 bytes mimeicons/text-x-csrc.png | Bin 3152 -> 0 bytes mimeicons/text-x-css.png | Bin 1531 -> 1526 bytes mimeicons/text-x-generic.png | Bin 1027 -> 781 bytes mimeicons/text-x-go.png | Bin 4613 -> 3438 bytes mimeicons/text-x-javascript.png | Bin 3046 -> 2260 bytes mimeicons/text-x-preview.png | Bin 521 -> 433 bytes mimeicons/text-x-python.png | Bin 3255 -> 2517 bytes mimeicons/text-x-script.png | Bin 1130 -> 846 bytes mimeicons/text-x-vala.png | Bin 2669 -> 2018 bytes mimeicons/video-x-generic.png | Bin 728 -> 541 bytes mimeicons/x-office-calendar.png | Bin 1487 -> 1225 bytes mimeicons/x-office-document-template.png | Bin 2596 -> 2097 bytes mimeicons/x-office-document.png | Bin 1207 -> 903 bytes mimeicons/x-office-drawing-template.png | Bin 3690 -> 2968 bytes mimeicons/x-office-drawing.png | Bin 2994 -> 2349 bytes mimeicons/x-office-presentation-template.png | Bin 2432 -> 1998 bytes mimeicons/x-office-presentation.png | Bin 1446 -> 1084 bytes mimeicons/x-office-spreadsheet-template.png | Bin 2009 -> 1774 bytes mimeicons/x-office-spreadsheet.png | Bin 762 -> 584 bytes 37 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 mimeicons/text-x-c.png delete mode 100644 mimeicons/text-x-csrc.png diff --git a/loggedin.js b/loggedin.js index 9a37c91..a98ef8b 100644 --- a/loggedin.js +++ b/loggedin.js @@ -406,7 +406,9 @@ function make_window(pwd) { function add_file_visuals(fileview) { - var is_in_trash = focus.pwd.length == 1 && focus.pwd[0] == "trash"; + // Are we in a subdirectory of the trash folder + var is_in_trash = focus.pwd.length > 0 && focus.pwd[0] == "trash"; + // Is the current filewview the trash folder itself var is_trash = focus.pwd.length == 0 && fileview.filename == "trash"; var visuals = document.createElement('div'); @@ -458,7 +460,7 @@ function add_file_visuals(fileview) { } visuals.ondragstart = (e) => { - if (focus.pwd.length == 0 && fileview.filename == "trash") { + if (is_trash || is_in_trash) { e.preventDefault(); return; } diff --git a/mimeicons/application-octet-stream.png b/mimeicons/application-octet-stream.png index 741abd2..327ff28 100644 Binary files a/mimeicons/application-octet-stream.png and b/mimeicons/application-octet-stream.png differ diff --git a/mimeicons/application-pdf.png b/mimeicons/application-pdf.png index a5589da..7935b68 100644 Binary files a/mimeicons/application-pdf.png and b/mimeicons/application-pdf.png differ diff --git a/mimeicons/application-rss_xml.png b/mimeicons/application-rss_xml.png index 22095de..39ea360 100644 Binary files a/mimeicons/application-rss_xml.png and b/mimeicons/application-rss_xml.png differ diff --git a/mimeicons/application-x-bittorrent.png b/mimeicons/application-x-bittorrent.png index f1d5ddd..50b292f 100644 Binary files a/mimeicons/application-x-bittorrent.png and b/mimeicons/application-x-bittorrent.png differ diff --git a/mimeicons/application-x-cd-image.png b/mimeicons/application-x-cd-image.png index 562c663..64cdbc8 100644 Binary files a/mimeicons/application-x-cd-image.png and b/mimeicons/application-x-cd-image.png differ diff --git a/mimeicons/application-x-executable.png b/mimeicons/application-x-executable.png index 7c65294..01602a4 100644 Binary files a/mimeicons/application-x-executable.png and b/mimeicons/application-x-executable.png differ diff --git a/mimeicons/application-x-object.png b/mimeicons/application-x-object.png index e8e1a9a..e8928ea 100644 Binary files a/mimeicons/application-x-object.png and b/mimeicons/application-x-object.png differ diff --git a/mimeicons/audio-x-generic.png b/mimeicons/audio-x-generic.png index 624c09c..33f7aef 100644 Binary files a/mimeicons/audio-x-generic.png and b/mimeicons/audio-x-generic.png differ diff --git a/mimeicons/font-x-generic.png b/mimeicons/font-x-generic.png index ab3d469..bf89e93 100644 Binary files a/mimeicons/font-x-generic.png and b/mimeicons/font-x-generic.png differ diff --git a/mimeicons/image-x-generic.png b/mimeicons/image-x-generic.png index 17071bb..1d5a936 100644 Binary files a/mimeicons/image-x-generic.png and b/mimeicons/image-x-generic.png differ diff --git a/mimeicons/package-x-generic.png b/mimeicons/package-x-generic.png index 1fca710..d435109 100644 Binary files a/mimeicons/package-x-generic.png and b/mimeicons/package-x-generic.png differ diff --git a/mimeicons/text-html.png b/mimeicons/text-html.png index 31ba1bd..d95975e 100644 Binary files a/mimeicons/text-html.png and b/mimeicons/text-html.png differ diff --git a/mimeicons/text-vnd.trolltech.linguist.png b/mimeicons/text-vnd.trolltech.linguist.png index 3cd52b3..221a83b 100644 Binary files a/mimeicons/text-vnd.trolltech.linguist.png and b/mimeicons/text-vnd.trolltech.linguist.png differ diff --git a/mimeicons/text-x-c.png b/mimeicons/text-x-c.png new file mode 100644 index 0000000..355acbf Binary files /dev/null and b/mimeicons/text-x-c.png differ diff --git a/mimeicons/text-x-changelog.png b/mimeicons/text-x-changelog.png index 0d3f7bf..fea4262 100644 Binary files a/mimeicons/text-x-changelog.png and b/mimeicons/text-x-changelog.png differ diff --git a/mimeicons/text-x-chdr.png b/mimeicons/text-x-chdr.png index adfc066..4cbe714 100644 Binary files a/mimeicons/text-x-chdr.png and b/mimeicons/text-x-chdr.png differ diff --git a/mimeicons/text-x-cpp.png b/mimeicons/text-x-cpp.png index fa76ba0..31dd7ad 100644 Binary files a/mimeicons/text-x-cpp.png and b/mimeicons/text-x-cpp.png differ diff --git a/mimeicons/text-x-csrc.png b/mimeicons/text-x-csrc.png deleted file mode 100644 index 6a9f2e8..0000000 Binary files a/mimeicons/text-x-csrc.png and /dev/null differ diff --git a/mimeicons/text-x-css.png b/mimeicons/text-x-css.png index 6d3b7e7..3bddf64 100644 Binary files a/mimeicons/text-x-css.png and b/mimeicons/text-x-css.png differ diff --git a/mimeicons/text-x-generic.png b/mimeicons/text-x-generic.png index 924a5eb..5dfec99 100644 Binary files a/mimeicons/text-x-generic.png and b/mimeicons/text-x-generic.png differ diff --git a/mimeicons/text-x-go.png b/mimeicons/text-x-go.png index 3ca93a6..7856ab2 100644 Binary files a/mimeicons/text-x-go.png and b/mimeicons/text-x-go.png differ diff --git a/mimeicons/text-x-javascript.png b/mimeicons/text-x-javascript.png index a37deb8..98051d0 100644 Binary files a/mimeicons/text-x-javascript.png and b/mimeicons/text-x-javascript.png differ diff --git a/mimeicons/text-x-preview.png b/mimeicons/text-x-preview.png index b86d1ca..3d7ae6e 100644 Binary files a/mimeicons/text-x-preview.png and b/mimeicons/text-x-preview.png differ diff --git a/mimeicons/text-x-python.png b/mimeicons/text-x-python.png index 05a7a7c..9435dcd 100644 Binary files a/mimeicons/text-x-python.png and b/mimeicons/text-x-python.png differ diff --git a/mimeicons/text-x-script.png b/mimeicons/text-x-script.png index e476856..0772cdf 100644 Binary files a/mimeicons/text-x-script.png and b/mimeicons/text-x-script.png differ diff --git a/mimeicons/text-x-vala.png b/mimeicons/text-x-vala.png index 81595dd..0fbe3e3 100644 Binary files a/mimeicons/text-x-vala.png and b/mimeicons/text-x-vala.png differ diff --git a/mimeicons/video-x-generic.png b/mimeicons/video-x-generic.png index 167c9d0..562ad3c 100644 Binary files a/mimeicons/video-x-generic.png and b/mimeicons/video-x-generic.png differ diff --git a/mimeicons/x-office-calendar.png b/mimeicons/x-office-calendar.png index 5da8bd3..0dbe9ed 100644 Binary files a/mimeicons/x-office-calendar.png and b/mimeicons/x-office-calendar.png differ diff --git a/mimeicons/x-office-document-template.png b/mimeicons/x-office-document-template.png index 834ebbe..ab1908b 100644 Binary files a/mimeicons/x-office-document-template.png and b/mimeicons/x-office-document-template.png differ diff --git a/mimeicons/x-office-document.png b/mimeicons/x-office-document.png index 20f5939..2e5a80f 100644 Binary files a/mimeicons/x-office-document.png and b/mimeicons/x-office-document.png differ diff --git a/mimeicons/x-office-drawing-template.png b/mimeicons/x-office-drawing-template.png index 34aa16d..86afd82 100644 Binary files a/mimeicons/x-office-drawing-template.png and b/mimeicons/x-office-drawing-template.png differ diff --git a/mimeicons/x-office-drawing.png b/mimeicons/x-office-drawing.png index 7239629..46bb9b1 100644 Binary files a/mimeicons/x-office-drawing.png and b/mimeicons/x-office-drawing.png differ diff --git a/mimeicons/x-office-presentation-template.png b/mimeicons/x-office-presentation-template.png index d1e9bff..38be81b 100644 Binary files a/mimeicons/x-office-presentation-template.png and b/mimeicons/x-office-presentation-template.png differ diff --git a/mimeicons/x-office-presentation.png b/mimeicons/x-office-presentation.png index dfc73b4..a1740b1 100644 Binary files a/mimeicons/x-office-presentation.png and b/mimeicons/x-office-presentation.png differ diff --git a/mimeicons/x-office-spreadsheet-template.png b/mimeicons/x-office-spreadsheet-template.png index dcec754..b46472d 100644 Binary files a/mimeicons/x-office-spreadsheet-template.png and b/mimeicons/x-office-spreadsheet-template.png differ diff --git a/mimeicons/x-office-spreadsheet.png b/mimeicons/x-office-spreadsheet.png index 03e7755..cfee058 100644 Binary files a/mimeicons/x-office-spreadsheet.png and b/mimeicons/x-office-spreadsheet.png differ -- cgit v1.2.3 From f31515a86ee23ef9f0cd0edf9c946ec5e9aa2b09 Mon Sep 17 00:00:00 2001 From: Alex Vitkov Date: Sat, 13 Feb 2021 16:47:18 +0200 Subject: image viewer 1.0 --- loggedin.js | 85 ++++++++++++++++++++++++++++++++++++++++++++--- mimeicons/image-jpeg.png | Bin 0 -> 409 bytes mimeicons/image-jpg.png | Bin 0 -> 409 bytes mimeicons/image-png.png | Bin 0 -> 409 bytes 4 files changed, 80 insertions(+), 5 deletions(-) create mode 100644 mimeicons/image-jpeg.png create mode 100644 mimeicons/image-jpg.png create mode 100644 mimeicons/image-png.png diff --git a/loggedin.js b/loggedin.js index a98ef8b..fff6054 100644 --- a/loggedin.js +++ b/loggedin.js @@ -63,6 +63,59 @@ function on_file_added(_e) { } } +// https://stackoverflow.com/questions/7370943/retrieving-binary-file-content-using-javascript-base64-encode-it-and-reverse-de +function base64ArrayBuffer(arrayBuffer) { + var base64 = '' + var encodings = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' + + var bytes = new Uint8Array(arrayBuffer) + var byteLength = bytes.byteLength + var byteRemainder = byteLength % 3 + var mainLength = byteLength - byteRemainder + + var a, b, c, d + var chunk + + // Main loop deals with bytes in chunks of 3 + for (var i = 0; i < mainLength; i = i + 3) { + // Combine the three bytes into a single integer + chunk = (bytes[i] << 16) | (bytes[i + 1] << 8) | bytes[i + 2] + + // Use bitmasks to extract 6-bit segments from the triplet + a = (chunk & 16515072) >> 18 // 16515072 = (2^6 - 1) << 18 + b = (chunk & 258048) >> 12 // 258048 = (2^6 - 1) << 12 + c = (chunk & 4032) >> 6 // 4032 = (2^6 - 1) << 6 + d = chunk & 63 // 63 = 2^6 - 1 + + // Convert the raw binary segments to the appropriate ASCII encoding + base64 += encodings[a] + encodings[b] + encodings[c] + encodings[d] + } + + // Deal with the remaining bytes and padding + if (byteRemainder == 1) { + chunk = bytes[mainLength] + + a = (chunk & 252) >> 2 // 252 = (2^6 - 1) << 2 + + // Set the 4 least significant bits to zero + b = (chunk & 3) << 4 // 3 = 2^2 - 1 + + base64 += encodings[a] + encodings[b] + '==' + } else if (byteRemainder == 2) { + chunk = (bytes[mainLength] << 8) | bytes[mainLength + 1] + + a = (chunk & 64512) >> 10 // 64512 = (2^6 - 1) << 10 + b = (chunk & 1008) >> 4 // 1008 = (2^6 - 1) << 4 + + // Set the 2 least significant bits to zero + c = (chunk & 15) << 2 // 15 = 2^4 - 1 + + base64 += encodings[a] + encodings[b] + encodings[c] + '=' + } + + return base64 +} + function update_path_visuals() { var the_path = focus.visuals.getElementsByClassName('path')[0]; @@ -92,6 +145,16 @@ function update_path_visuals() { } function openfile_nondir() { + var mimetype = "text/plain"; + + for (const f of files) { + if (f.filename == focus.pwd[focus.pwd.length - 1]) + mimetype = f.mimetype; + } + + while (focus.filecontents.children.length > 0) + focus.filecontents.removeChild(focus.filecontents.lastChild); + var data = new FormData(); data.append('folder', get_path(focus.pwd.length - 1)); data.append('filename', focus.pwd[focus.pwd.length - 1]); @@ -108,9 +171,21 @@ function openfile_nondir() { focus.filecontents.style.display = 'block'; focus.foldercontents.style.display = 'none'; - xhr.onload = function () { - focus.filecontents.innerText = xhr.responseText; - }; + if (mimetype.split("/")[0] == "image") { + xhr.responseType = 'arraybuffer'; + xhr.onload = function () { + var b = base64ArrayBuffer(xhr.response); + var image = new Image(); + image.src = `data:image/png;base64,${b}`; + focus.filecontents.appendChild(image); + } + } + else { + xhr.onload = function () { + focus.filecontents.innerText = xhr.responseText; + }; + } + xhr.send(data); } @@ -347,8 +422,8 @@ function make_window(pwd) { wnd_html.appendChild(h2); //h2.onmousedown = (e) => { - //begin_drag(e, wnd_html); - // e.preventDefault(); + //begin_drag(e, wnd_html); + // e.preventDefault(); //}; path = document.createElement('div'); diff --git a/mimeicons/image-jpeg.png b/mimeicons/image-jpeg.png new file mode 100644 index 0000000..1d5a936 Binary files /dev/null and b/mimeicons/image-jpeg.png differ diff --git a/mimeicons/image-jpg.png b/mimeicons/image-jpg.png new file mode 100644 index 0000000..1d5a936 Binary files /dev/null and b/mimeicons/image-jpg.png differ diff --git a/mimeicons/image-png.png b/mimeicons/image-png.png new file mode 100644 index 0000000..1d5a936 Binary files /dev/null and b/mimeicons/image-png.png differ -- cgit v1.2.3