F diff --git a/loggedin.js b/loggedin.js --- a/loggedin.js +++ b/loggedin.jsthe_file.onchange = on_file_added;var pwd = [];- const pending_uploads = [];var context_menu = null;+ var dragging = null;+ var dragging_placeholder = null;+ var dragging_offset_x = 0, dragging_offset_y = 0;class FileView {constructor(filename, visuals, mimetype, is_directory) {return;}- var fileview = add_file_visuals(filename_input.value, false, "pending");-// Send the form asynchronously through the fetch apifetch(upload_form.action, {method: upload_form.method,body: new FormData(upload_form)}).then((resp) => {if (resp.status == 200) {- done_upload(fileview);+ load_dir();} else {alert("Upload failed");}}, () => {alert("Upload failed")});-- pending_uploads.push(fileview);}else {alert("No files selected");}}- function done_upload(fileview) {- var index = pending_uploads.indexOf(fileview);- if (index >= 0)- pending_uploads.splice(index, 1);-- load_dir();- }-function load_dir() {-while (the_path.children.length > 1)the_path.removeChild(the_path.lastChild);files = [];var json = JSON.parse(this.responseText);- console.log(json);for (const f of json) {- add_file_visuals(f.name, f.is_directory && f.is_directory != "0", f.mimetype);+ var view = new FileView(f.name, null, f.mimetype, f.is_directory && f.is_directory != "0");+ files.push(view);}++ files.sort((a, b) => {+ if (a.is_directory && !b.is_directory)+ return -1;+ if (!a.is_directory && b.is_directory)+ return 1;+ return a.filename.localeCompare(b.filename);+ });++ for (const f of files) {+ add_file_visuals(f);+ }+};xhr.send(data);}xhr.send(data);}- function add_file_visuals(name, is_directory, mimetype) {- var fileDiv = document.createElement('div');+ function begin_drag(e, fileview) {+ if (dragging) {+ alert("AAAAAAAAAAAAAA");+ }++ dragging_placeholder = document.createElement('div');+ fileview.visuals.parentNode.insertBefore(dragging_placeholder, fileview.visuals);++ dragging = fileview.visuals;++ var elemRect = dragging.getBoundingClientRect();++ dragging_offset_x = elemRect.width - (elemRect.left - e.clientX);+ dragging_offset_y = elemRect.top - e.clientY;++ dragging.style.position = "absolute";+ dragging.style.top = "0px";+ dragging.style.left = "0px";+ dragging.style.width = elemRect.width + "px";+ dragging.style.height = elemRect.height + "px";+ document.body.appendChild(dragging);+ }++ function add_file_visuals(fileview) {+ var visuals = document.createElement('div');+ fileview.visuals = visuals;var img = document.createElement('img');var filename = document.createElement('div');- if (is_directory!=0) {+ if (fileview.is_directory!=0) {img.src="/mimeicons/directory.png";- fileDiv.onclick = () => {+ visuals.onclick = () => {pwd.push(name);load_dir();}} else {- img.src=`/mimeicons/${mimetype.replace("/", "-")}.png`;+ img.src=`/mimeicons/${fileview.mimetype.replace("/", "-")}.png`;}- fileDiv.oncontextmenu = (e) => {+ visuals.oncontextmenu = (e) => {context(e, [['Open', () => {if (is_directory) {e.preventDefault();}- fileDiv.classList.add('file');- filename.classList.add('filename');- filename.innerText = name;+ visuals.ondragstart = (e) => {+ begin_drag(e, fileview);+ e.preventDefault();+ };- if (mimetype == "pending")- fileDiv.classList.add('pending');+ visuals.classList.add('file');+ filename.classList.add('filename');+ filename.innerText = fileview.filename;- fileDiv.appendChild(img);- fileDiv.appendChild(filename);+ if (fileview.mimetype == "pending")+ visuals.classList.add('pending');- current_directory.appendChild(fileDiv);+ visuals.appendChild(img);+ visuals.appendChild(filename);- var file = new FileView(name, fileDiv, mimetype, is_directory);- files.push(file);- return file;+ current_directory.appendChild(visuals);}function begin_upload() {context_menu.style.left = e.clientX + "px";context_menu.style.top = e.clientY + "px";-for (const e of entries) {const li = document.createElement('li');li.innerText = e[0];context_menu.remove();}+ document.body.onmousemove = (e) => {+ if (dragging) {+ dragging.style.left = (e.clientX - dragging_offset_x) + "px";+ dragging.style.top = (e.clientY + dragging_offset_y) + "px";+ }+ }+load_dir();F diff --git a/mimeicons/application-x-empty.png b/mimeicons/application-x-empty.png new file mode 100644B Binary files /dev/null and b/mimeicons/application-x-empty.png differF diff --git a/php/database.php b/php/database.php --- a/php/database.php +++ b/php/database.php}/*if both are not null returns the id of the node with the name name in the directory_id node*/- function get_node_id(string $name,int $directory_id)+ function get_node_id($name,$directory_id){- $statement=$this->pdo->prepare("- select node_links.node_id as id- from node_links- inner join nodes on- nodes.node_id=node_links.node_id- where node_links.name=:name and node_links.directory_id=:directory_id- ");+ $statement=$this->pdo->prepare(+ "select nl.node_id as id from node_links nl+ inner join nodes n on n.node_id=nl.node_id+ where name=:name and directory_id=:directory_id)");$statement->bindParam(':name',$name);$statement->bindParam(':directory_id',$directory_id);if($statement->execute()==false)return NULL;}$hold=$statement->fetch(PDO::FETCH_ASSOC);- if(gettype($hold)!="array")+ if($hold==false){return NULL;}elsereturn "error";}- /*check if node with given name exists*/- if($this->get_node_id($filename,$dir_id)!=NULL)- {- error_log("filename taken");- return "filename taken";- }/*generate the node*/$code=$this->get_random_node_name("");if($filename==NULL)return "error";F diff --git a/php/upload.php b/php/upload.php --- a/php/upload.php +++ b/php/upload.phphttp_response_code(400);exit(0);}- if($codename=="filename taken")- {- http_response_code(409);- exit(0);- }move_uploaded_file($file['tmp_name'], "$storage_root/$codename");http_response_code(200);