F diff --git a/loggedin.js b/loggedin.js --- a/loggedin.js +++ b/loggedin.js}}- // 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];}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]);xhr.open('POST', '/php/readfile.php', true);- focus.filecontents.innerText = "";+ focus.filecontents.innerText = "Loading...";focus.filecontents.style.display = 'block';focus.foldercontents.style.display = 'none';- 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.onload = function () {+ focus.filecontents.innerText = xhr.responseText;+ };xhr.send(data);}move_file("/trash", filename, 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 file_full_path = path_combine(get_path(), filename);+var data = new FormData();- data.append('folder', get_path());- data.append('filename', filename);+ data.append('path', file_full_path);var xhr = new XMLHttpRequest();xhr.open('POST', '/php/delete.php', true);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');function add_file_visuals(fileview) {- // 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');fileview.visuals = visuals;visuals.oncontextmenu = (e) => {if (!dragging) {-- var context_list = [+ context(e, [['Open', () => {focus.pwd.push(fileview.filename);openfile(fileview.is_directory);- }],+ }],['Open in New Window', () => {alert('not implemented')}],- ];-- if (is_in_trash) {- context_list.push(['Restore', () => { restore_from_trash(fileview.filename); }]);- context_list.push(['Delete forever', () => { delete_file(fileview.filename); }]);- } else if (!is_trash) {- context_list.push(- ['Rename', () => { rename_file(fileview.filename); }],- ['Share', () => {alert('not implemented')}],- ['Delete', () => { move_to_trash(fileview.filename); }]- );- }-- context(e, context_list);+ ['Rename', () => { rename_file(fileview.filename); }],+ ['Share', () => {alert('not implemented')}],+ ['Delete', () => { move_to_trash(fileview.filename); }],+ ]);}e.preventDefault();e.stopPropagation();}visuals.ondragstart = (e) => {- if (is_trash || is_in_trash) {- e.preventDefault();- return;- }begin_drag_fileview(e, fileview);e.preventDefault();};visuals.classList.add('file');filename.classList.add('filename');+ filename.innerText = fileview.filename;- 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;- }+ if (fileview.mimetype == "pending")+ visuals.classList.add('pending');visuals.appendChild(img);visuals.appendChild(filename);F diff --git a/mimeicons/application-octet-stream.png b/mimeicons/application-octet-stream.pngB Binary files a/mimeicons/application-octet-stream.png and b/mimeicons/application-octet-stream.png differF diff --git a/mimeicons/application-pdf.png b/mimeicons/application-pdf.pngB Binary files a/mimeicons/application-pdf.png and b/mimeicons/application-pdf.png differF diff --git a/mimeicons/application-rss_xml.png b/mimeicons/application-rss_xml.pngB Binary files a/mimeicons/application-rss_xml.png and b/mimeicons/application-rss_xml.png differF diff --git a/mimeicons/application-x-bittorrent.png b/mimeicons/application-x-bittorrent.pngB Binary files a/mimeicons/application-x-bittorrent.png and b/mimeicons/application-x-bittorrent.png differF diff --git a/mimeicons/application-x-cd-image.png b/mimeicons/application-x-cd-image.pngB Binary files a/mimeicons/application-x-cd-image.png and b/mimeicons/application-x-cd-image.png differF diff --git a/mimeicons/application-x-executable.png b/mimeicons/application-x-executable.pngB Binary files a/mimeicons/application-x-executable.png and b/mimeicons/application-x-executable.png differF diff --git a/mimeicons/application-x-object.png b/mimeicons/application-x-object.pngB Binary files a/mimeicons/application-x-object.png and b/mimeicons/application-x-object.png differF diff --git a/mimeicons/audio-x-generic.png b/mimeicons/audio-x-generic.pngB Binary files a/mimeicons/audio-x-generic.png and b/mimeicons/audio-x-generic.png differF diff --git a/mimeicons/font-x-generic.png b/mimeicons/font-x-generic.pngB Binary files a/mimeicons/font-x-generic.png and b/mimeicons/font-x-generic.png differF diff --git a/mimeicons/image-jpeg.png b/mimeicons/image-jpeg.png deleted file mode 100644B Binary files a/mimeicons/image-jpeg.png and /dev/null differF diff --git a/mimeicons/image-jpg.png b/mimeicons/image-jpg.png deleted file mode 100644B Binary files a/mimeicons/image-jpg.png and /dev/null differF diff --git a/mimeicons/image-png.png b/mimeicons/image-png.png deleted file mode 100644B Binary files a/mimeicons/image-png.png and /dev/null differF diff --git a/mimeicons/image-x-generic.png b/mimeicons/image-x-generic.pngB Binary files a/mimeicons/image-x-generic.png and b/mimeicons/image-x-generic.png differF diff --git a/mimeicons/package-x-generic.png b/mimeicons/package-x-generic.pngB Binary files a/mimeicons/package-x-generic.png and b/mimeicons/package-x-generic.png differF diff --git a/mimeicons/text-html.png b/mimeicons/text-html.pngB Binary files a/mimeicons/text-html.png and b/mimeicons/text-html.png differF diff --git a/mimeicons/text-vnd.trolltech.linguist.png b/mimeicons/text-vnd.trolltech.linguist.pngB Binary files a/mimeicons/text-vnd.trolltech.linguist.png and b/mimeicons/text-vnd.trolltech.linguist.png differF diff --git a/mimeicons/text-x-c.png b/mimeicons/text-x-c.png deleted file mode 100644B Binary files a/mimeicons/text-x-c.png and /dev/null differF diff --git a/mimeicons/text-x-changelog.png b/mimeicons/text-x-changelog.pngB Binary files a/mimeicons/text-x-changelog.png and b/mimeicons/text-x-changelog.png differF diff --git a/mimeicons/text-x-chdr.png b/mimeicons/text-x-chdr.pngB Binary files a/mimeicons/text-x-chdr.png and b/mimeicons/text-x-chdr.png differF diff --git a/mimeicons/text-x-cpp.png b/mimeicons/text-x-cpp.pngB Binary files a/mimeicons/text-x-cpp.png and b/mimeicons/text-x-cpp.png differF diff --git a/mimeicons/text-x-csrc.png b/mimeicons/text-x-csrc.png new file mode 100644B Binary files /dev/null and b/mimeicons/text-x-csrc.png differF diff --git a/mimeicons/text-x-css.png b/mimeicons/text-x-css.pngB Binary files a/mimeicons/text-x-css.png and b/mimeicons/text-x-css.png differF diff --git a/mimeicons/text-x-generic.png b/mimeicons/text-x-generic.pngB Binary files a/mimeicons/text-x-generic.png and b/mimeicons/text-x-generic.png differF diff --git a/mimeicons/text-x-go.png b/mimeicons/text-x-go.pngB Binary files a/mimeicons/text-x-go.png and b/mimeicons/text-x-go.png differF diff --git a/mimeicons/text-x-javascript.png b/mimeicons/text-x-javascript.pngB Binary files a/mimeicons/text-x-javascript.png and b/mimeicons/text-x-javascript.png differF diff --git a/mimeicons/text-x-preview.png b/mimeicons/text-x-preview.pngB Binary files a/mimeicons/text-x-preview.png and b/mimeicons/text-x-preview.png differF diff --git a/mimeicons/text-x-python.png b/mimeicons/text-x-python.pngB Binary files a/mimeicons/text-x-python.png and b/mimeicons/text-x-python.png differF diff --git a/mimeicons/text-x-script.png b/mimeicons/text-x-script.pngB Binary files a/mimeicons/text-x-script.png and b/mimeicons/text-x-script.png differF diff --git a/mimeicons/text-x-vala.png b/mimeicons/text-x-vala.pngB Binary files a/mimeicons/text-x-vala.png and b/mimeicons/text-x-vala.png differF diff --git a/mimeicons/video-x-generic.png b/mimeicons/video-x-generic.pngB Binary files a/mimeicons/video-x-generic.png and b/mimeicons/video-x-generic.png differF diff --git a/mimeicons/x-office-calendar.png b/mimeicons/x-office-calendar.pngB Binary files a/mimeicons/x-office-calendar.png and b/mimeicons/x-office-calendar.png differF diff --git a/mimeicons/x-office-document-template.png b/mimeicons/x-office-document-template.pngB Binary files a/mimeicons/x-office-document-template.png and b/mimeicons/x-office-document-template.png differF diff --git a/mimeicons/x-office-document.png b/mimeicons/x-office-document.pngB Binary files a/mimeicons/x-office-document.png and b/mimeicons/x-office-document.png differF diff --git a/mimeicons/x-office-drawing-template.png b/mimeicons/x-office-drawing-template.pngB Binary files a/mimeicons/x-office-drawing-template.png and b/mimeicons/x-office-drawing-template.png differF diff --git a/mimeicons/x-office-drawing.png b/mimeicons/x-office-drawing.pngB Binary files a/mimeicons/x-office-drawing.png and b/mimeicons/x-office-drawing.png differF diff --git a/mimeicons/x-office-presentation-template.png b/mimeicons/x-office-presentation-template.pngB Binary files a/mimeicons/x-office-presentation-template.png and b/mimeicons/x-office-presentation-template.png differF diff --git a/mimeicons/x-office-presentation.png b/mimeicons/x-office-presentation.pngB Binary files a/mimeicons/x-office-presentation.png and b/mimeicons/x-office-presentation.png differF diff --git a/mimeicons/x-office-spreadsheet-template.png b/mimeicons/x-office-spreadsheet-template.pngB Binary files a/mimeicons/x-office-spreadsheet-template.png and b/mimeicons/x-office-spreadsheet-template.png differF diff --git a/mimeicons/x-office-spreadsheet.png b/mimeicons/x-office-spreadsheet.pngB Binary files a/mimeicons/x-office-spreadsheet.png and b/mimeicons/x-office-spreadsheet.png differF diff --git a/php/database.php b/php/database.php --- a/php/database.php +++ b/php/database.phpwe remove the node and1. move the file represented by the node to the trash folder2. remove the file- 3. if node is a directory - delete all children nodesdepends on the conf file*/function delete_node_by_id(int $node_id)}- function unlink_nodes(int $dir_id, int $node_id)+ function unlink_nodes(int $dir_id, string $filename){$prep=$this->pdo->prepare("delete from node_links- where directory_id=:dir_id and node_id=:node_id+ where directory_id=:dir_id and name=:name");$prep->bindParam(':dir_id',$dir_id);- $prep->bindParam(':node_id',$node_id);+ $prep->bindParam(':name',$filename);if($prep->execute()==false){error_log("there was an error with the first statement in unlink_nodes");return;}- $prep=$this->pdo->prepare("select node_id- from node_links- where node_id=:id- ");- $prep->bindParam(':id',$node_id);- if($prep->execute()==false)- {- error_log("there was an error with the second statement in unlink_nodes");- return;- }- if(count($prep->fetchALL(PDO::FETCH_ASSOC))==0)- {- delete_node_by_id($node_id);+ do{+ $prep=$this->pdo->prepare("select count(1) as count from trash");+ $prep->execute() or die(1);+ $res=$prep->fetch(PDO::FETCH_ASSOC);+ $prep=$this->pdo->prepare("insert into super_trash select node_id from trash");+ $prep->execute() or die(1);+ $prep=$this->pdo->prepare("delete from trash");+ $prep->execute() or die(1);+ $prep=$this->pdo->prepare("delete from links+ where directory_id in+ (select node_id from super_trash)+ ");+ $prep->execute() or die(1);++ }while($res["count"]!=0);+ $prep=$this->pdo->prepare("select code from nodes where node_id in+ (select node_id from super_trash)");+ $prep->execute() or die(1);+ $res=$prep->fetchAll(PDO::FETCH_ASSOC);+ foreach($res as $node)+ {+ unlink($storage_root,"/".$node["code"]);}+ $prep=$this->pdo->prepare("delete from nodes where node_id in+ (select node_id from super_trash");+ $prep->execute() or die(1);+ $prep=$this->pdo->prepare("delete from super_trash");}F diff --git a/sql/fileshare.sql b/sql/fileshare.sql --- a/sql/fileshare.sql +++ b/sql/fileshare.sqldrop table if exists users;drop table if exists node_links;drop table if exists trash;+ drop table if exists super_trash;drop trigger if exists delete_on_zero_links;+ drop trigger if exists delete_links;+ drop trigger if exists del_node;drop table if exists nodes;create table trash (node_id int not null,- foreign key (node_id) references nodes(node_id) on delete cascade+ foreign key (node_id) references nodes(node_id));+ create table super_trash (+ node_id int not null,+ foreign key (node_id) references nodes(node_id)+ );create trigger delete_on_zero_linksinsert into trashselect nodes.node_idfrom nodes- where nodes.node_id not in (select node_id from node_links) and nodes.node_id=old.node_id;+ where nodes.node_id not in (select node_id from node_links) and nodes.node_id=old.node_id ;- /*create trigger delete_linksafter deleteon nodesfor each row- delete from+ delete from node_links where directory_id=old.node_id;+ /*+ create trigger del_node+ after insert+ on trash+ for each row+ delete from nodes where node_id=new.node_id;*/