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/database.php b/php/database.php --- a/php/database.php +++ b/php/database.php
we remove the node and
1. move the file represented by the node to the trash folder
2. remove the file
- 3. if node is a directory - delete all children nodes
depends on the conf file
*/
function delete_node_by_id(int $node_id)
}
}
-
- function unlink_nodes(int $dir_id, int $node_id)
- {
- $prep=$this->pdo->prepare("delete from node_links
- where directory_id=:dir_id and node_id=:node_id
- ");
- $prep->bindParam(':dir_id',$dir_id);
- $prep->bindParam(':node_id',$node_id);
- 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);
- }
-
-
- }
-
function create_home_directory():int
{
$ret=$this->create_dangling_directory();
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");
F diff --git a/sql/fileshare.sql b/sql/fileshare.sql --- a/sql/fileshare.sql +++ b/sql/fileshare.sql
drop table if exists node_access;
drop table if exists users;
drop table if exists node_links;
- drop table if exists trash;
- drop trigger if exists delete_on_zero_links;
drop table if exists nodes;
node_id int not null,
name varchar(100) not null default 'no name',
note varchar(200) not null default "",
+ check (directory_id != node_id),
foreign key (directory_id) references nodes(node_id) on delete cascade,
foreign key (node_id) references nodes(node_id) on delete cascade
);
- create table trash (
- node_id int not null,
- foreign key (node_id) references nodes(node_id) on delete cascade
- );
-
- /*
- create trigger delete_on_zero_links
- after delete
- on node_links
- for each row
- insert into trash(node_id)
- select
- if(old.node_id not in (select node_id from node_links),
- old.node_id,
- select node_id from nodes where 1=0
- );
-
- */