FILEUP



LOG | FILES | OVERVIEW


F diff --git a/INIT_DATABASE.sql b/INIT_DATABASE.sql --- a/INIT_DATABASE.sql +++ b/INIT_DATABASE.sql
drop table if exists super_trash;
drop table if exists shared_nodes;
drop table if exists nodes;
- drop table if exists email_verification_codes;
drop trigger if exists supper_del_node;
- drop view if exists usernames;
node_id int not null
);
- create table email_verification_codes (
- verification_id int not null auto_increment,
- verification_code varchar(100) not null,
- username varchar(50) not null unique,
- password varchar(255) not null,
- email varchar(50),
- primary key (verification_id)
- );
create trigger delete_on_zero_links
after delete
delete from node_links
where directory_id=old.node_id;
- create view usernames
- as
- select username from users
- union
- select username from email_verification_codes;
+
F diff --git a/css/style.css b/css/style.css --- a/css/style.css +++ b/css/style.css
background: white;
}
- .window h3 > .separator {
+ .window h3 .separator {
flex: 0 0 1px;
align-self: stretch;
background: #bbb;
F diff --git a/loggedin.js b/loggedin.js --- a/loggedin.js +++ b/loggedin.js
this.h2 = null; // The titlebar of the window
this.fileview = null;
this.files = [];
+ this.txt_editor = null; // For editable text files, this is the DOM element the user can edit
}
}
var override_file_filename = "";
var override_file_path = "";
- var open_file_mimetype = null;
+ var open_file = null;
// Some elements have custom right click context menus
// If there's a custom context menu active, this will be it
focus.filecontentsroot.style.display = 'flex';
focus.foldercontents.style.display = 'none';
- if (open_file_mimetype.split("/")[0] == "image") {
+ let is_image = open_file.mimetype.split("/")[0] == "image";
+ focus.save_btn_container.style.display = (open_file.write_permissions && !is_image) ? "flex" : "none";
+
+ if (is_image) {
xhr.responseType = 'arraybuffer';
xhr.onload = function () {
let b = `data:image/png;base64,${base64ArrayBuffer(xhr.response)}`;
focus.filecontents.classList.remove('imgview');
focus.filecontents.style.backgroundImage = "unset";
- var pre = mk(focus.filecontents, 'pre');
+ focus.txt_editor = mk(focus.filecontents, 'pre');
xhr.onload = function () {
- pre.innerText = xhr.responseText;
- pre.contentEditable = "true";
+ focus.txt_editor.innerText = xhr.responseText;
+ focus.txt_editor.contentEditable = "true";
};
}
share_btn.onclick = () => { share(true); }
mk(h3, 'div', 'separator');
- let replace_btn = mk(h3, 'button');
- replace_btn.innerText = "Save Changes";
- replace_btn.onclick = () => { alert("No implemento"); }
- mk(h3, 'div', 'separator');
+ wnd.save_btn_container = mk(h3, 'div');
+ wnd.save_btn_container.style.display = 'flex';
+
+ let save_btn = mk(wnd.save_btn_container, 'button');
+ save_btn.innerText = "Save";
+ save_btn.onclick = save_open_text_file;
+ mk(wnd.save_btn_container, 'div', 'separator');
wnd.filecontents = mk(wnd.filecontentsroot, 'div', 'filecontents');
}
}
+ function save_open_text_file() {
+ const contents = focus.txt_editor.innerText;
+ let xhr = new XMLHttpRequest();
+ xhr.open('POST', '/php/upload.php', true);
+
+ var data = new FormData();
+ data.append('parent_directory', get_path (focus.pwd.length - 1));
+ data.append('filename', focus.pwd[focus.pwd.length - 1]);
+ data.append('content', contents);
+ data.append('overwrite', '1');
+
+ xhr.send(data);
+ }
+
+
// Create the visuals for a FileView
function add_file_visuals(fileview) {
// Are we in a subdirectory of the trash folder?
fileview.visuals.onclick = () => {
focus.pwd.push(fileview.filename);
- if (!fileview.is_directory)
- open_file_mimetype = fileview.mimetype;
+ if (!fileview.is_directory) {
+ open_file = fileview;
+ }
openfile(fileview.is_directory);
}
new_pwd.push(fileview.filename);
var new_wnd = make_window(new_pwd, true);
focus_window(new_wnd);
- open_file_mimetype = fileview.mimetype;
+ open_file = fileview;
openfile(fileview.is_directory);
}],
];
F diff --git a/php/upload.php b/php/upload.php --- a/php/upload.php +++ b/php/upload.php
require_once "node.php";
session_start();
- if (!isset( $_POST["filename"]) || (!isset($_FILES["the_file"]) && (!isset($_POST['content'] || gettype($_POST['content'])!="string"))|| !isset($_POST['parent_directory']) || !isset($_POST['overwrite']))
+ if (!isset( $_POST["filename"]) || !isset($_FILES["the_file"]) || !isset($_POST['parent_directory']) || !isset($_POST['overwrite']))
{
error_log("someone tried to upload something impropperly");
http_response_code(400);
http_response_code(409);
exit(0);
}
- if(isset($_POST['content']))
- {
- file_put_contents("$storage_root/$codename",$_POST['content']);
- }else
- {
- unlink("$storage_root/$codename");
- move_uploaded_file($file['tmp_name'], "$storage_root/$codename");
- }
+ unlink("$storage_root/$codename");
+ move_uploaded_file($file['tmp_name'], "$storage_root/$codename");
http_response_code(200);
exit(0);