FILEUP



LOG | FILES | OVERVIEW


F diff --git a/css/style.css b/css/style.css --- a/css/style.css +++ b/css/style.css
}
.filecontents {
+ background: white;
+ }
+
+ .filecontents {
padding: 0.8rem;
font-size: 1.1rem;
}
F diff --git a/loggedin.js b/loggedin.js --- a/loggedin.js +++ b/loggedin.js
}
function opendir() {
-
update_path_visuals();
var data = new FormData();
}
files.sort((a, b) => {
- if (a.is_directory && !b.is_directory)
- return -1;
- if (!a.is_directory && b.is_directory)
- return 1;
+ if (get_path() == "/" && a.filename == "trash")
+ return 2;
+ if (a.is_directory && !b.is_directory)
+ return -1;
+ if (!a.is_directory && b.is_directory)
+ return 1;
return a.filename.localeCompare(b.filename);
});
}
}
+ 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);
xhr.send(data);
}
- function move_file(new_folder, filename) {
+ function move_file(new_folder, filename, new_filename) {
+ if (!new_filename)
+ new_filename = filename;
+
var data = new FormData();
- data.append('old_folder', get_path());
- data.append('new_folder', new_folder);
- data.append('filename', filename);
+ data.append('old_folder', get_path());
+ data.append('new_folder', new_folder);
+ data.append('filename', filename);
+ data.append('new_filename',new_filename);
var xhr = new XMLHttpRequest();
xhr.open('POST', '/php/move.php', true);
var elemRect = dragging.getBoundingClientRect();
dragging_offset_x = e.clientX - elemRect.left;
dragging_offset_y = -e.clientY + elemRect.top;
-
+
if (dragging_placeholder)
obj.parentNode.insertBefore(dragging_placeholder, obj);
function drop_handler(dst, src) {
if (dst.is_directory) {
- move_file(path_combine(get_path(), dst.filename), src.filename);
+ if (get_path() == "/" && dst.filename == "trash") {
+ move_to_trash(src.filename);
+ } else {
+ move_file(path_combine(get_path(), dst.filename), src.filename);
+ }
} else {
alert(`Dropped ${dst.filename} on ${src.filename}`);
}
}
function add_link_functionality(link, length) {
- link.onclick = () => {
+ link.onclick = (e) => {
focus.pwd.length = length,
- openfile(true);
+ openfile(true);
}
link.onmouseup = (e) => {
var h2 = document.createElement('h2');
wnd_html.appendChild(h2);
- h2.onmousedown = (e) => {
- begin_drag(e, wnd_html);
- e.preventDefault();
- };
+ //h2.onmousedown = (e) => {
+ //begin_drag(e, wnd_html);
+ // e.preventDefault();
+ //};
path = document.createElement('div');
path.classList.add('path');
var filename = document.createElement('div');
if (fileview.is_directory) {
- if (fileview.filename == "trash")
+ if (get_path() == "/" && fileview.filename == "trash")
img.src="/mimeicons/user-trash.png";
else
img.src="/mimeicons/directory.png";
['Open in New Window', () => {alert('not implemented')}],
['Rename', () => { rename_file(fileview.filename); }],
['Share', () => {alert('not implemented')}],
- ['Delete', () => { delete_file(fileview.filename); }],
+ ['Delete', () => { move_to_trash(fileview.filename); }],
]);
}
e.preventDefault();
F diff --git a/php/move.php b/php/move.php --- a/php/move.php +++ b/php/move.php
exit(1);
}
- $filename = $_POST["filename"];
+ $new_filename = $_POST["filename"];
+ $old_filename = $_POST["filename"];
+
+ if (isset($_POST['new_filename']))
+ $new_filename = $_POST['new_filename'];
+
$old_folder = $_POST["old_folder"];
$new_folder = $_POST["new_folder"];
$user = $_SESSION['user_object'];
// Check if the filename is taken in the new dir
$contents_of_new_dir = $database->get_links_of($new_dir);
foreach ($contents_of_new_dir as $c) {
- if ($c['name'] == $filename) {
- error_log("filename $filename taken in $new_folder");
+ if ($c['name'] == $new_filename) {
+ error_log("filename $new_filename taken in $new_folder");
http_response_code(409);
exit(0);
}
$file_node = null;
$contents_of_old_dir = $database->get_links_of($old_dir);
foreach ($contents_of_old_dir as $c) {
- if ($c['name'] == $filename) {
+ if ($c['name'] == $old_filename) {
$file_node = $c['id'];
break;
}
}
if ($file_node == null) {
- error_log("/php/move.php failed - file $old_folder/$filename doesn't exist");
+ error_log("/php/move.php failed - file $old_folder/$new_filename doesn't exist");
http_response_code(409);
exit(0);
}
// Update the node_link
$move = $database->pdo->prepare("
UPDATE node_links
- SET directory_id = :new_dir
+ SET directory_id = :new_dir,
+ name = :new_filename
WHERE directory_id = :old_dir
AND node_id = :file_node
- AND name = :filename
+ AND name = :old_filename
");
- $move->bindParam(':new_dir', $new_dir);
- $move->bindParam(':old_dir', $old_dir);
- $move->bindParam(':file_node', $file_node);
- $move->bindParam(':filename', $filename);
+ $move->bindParam(':new_dir', $new_dir);
+ $move->bindParam(':old_dir', $old_dir);
+ $move->bindParam(':file_node', $file_node);
+ $move->bindParam(':old_filename', $old_filename);
+ $move->bindParam(':new_filename', $new_filename);
if(!$move->execute()) {
error_log("extremely sad shit");