From ffa3fc9a25555b9ac46f5d9cd181571478a80e2e Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 14 Oct 2022 13:22:01 +0200 Subject: [PATCH] Small fixes --- backend/src/main.rs | 9 ++- .../src/components/DirViewer/DirViewer.vue | 1 + .../components/DirViewer/DirViewerTable.vue | 76 +++++++++++++++---- 3 files changed, 71 insertions(+), 15 deletions(-) diff --git a/backend/src/main.rs b/backend/src/main.rs index 231e6ff..9230732 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -39,7 +39,7 @@ fn handle_request(mut req: Request, db: db::DBPool) { if !(path.contains('\\') || path.contains("..") || path.contains(':')) { let path_str = "./static".to_owned() + &path; let path = std::path::Path::new(&path_str); - if path.exists() { + if path.is_file() { let resp = Response::from_file(File::open(path).unwrap()); match path.extension().map(|s| s.to_str()).unwrap_or(None) { Some("html") => resp.with_header(header("content-type", "text/html; charset=utf-8")), @@ -175,10 +175,12 @@ fn handle_api_request(span: &mut Span, req: &mut Request, pool: db::DBPool) -> R } fn main() { + println!("Loading config..."); let _ = config::CONFIG; let db_pool: db::DBPool = db::build_pool(); + println!("Running migrations..."); db::run_migrations(&mut db_pool.get().unwrap()); if !std::path::Path::new("files").exists() { @@ -188,11 +190,13 @@ fn main() { if !std::path::Path::new("temp").is_dir() { std::fs::create_dir("temp").expect("Failed to create temp dir"); } + println!("Cleaning up temp..."); std::fs::read_dir("temp").expect("Failed to iter temp dir").for_each(|dir| { std::fs::remove_file(dir.expect("Failed to retrieve temp dir entry").path()) .expect("Failed to delete file in temp dir"); }); + println!("Loading metrics..."); metrics::init(DBConnection::from(db_pool.get().unwrap())); let shutdown = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false)); @@ -213,6 +217,7 @@ fn main() { .build() .unwrap(); + println!("Listening on 0.0.0.0:2345"); 'server: loop { match server.recv() { Ok(req) => { @@ -226,5 +231,5 @@ fn main() { } } - println!("Quitting"); + println!("Goodbye"); } diff --git a/frontend/src/components/DirViewer/DirViewer.vue b/frontend/src/components/DirViewer/DirViewer.vue index b8e036f..4a45e78 100644 --- a/frontend/src/components/DirViewer/DirViewer.vue +++ b/frontend/src/components/DirViewer/DirViewer.vue @@ -113,6 +113,7 @@ function createNewFolderDialog() { ; const props = defineProps<{ + currentNode: Responses.GetNode; nodes: Responses.GetNodeEntry[]; showPreview: boolean; }>(); @@ -65,6 +67,7 @@ const checkedRows = ref([]); const deleteNodes = ref([]); const deleteDialog = ref(); const deleteDialogShow = ref(false); +const cutNodes = ref([]); const dropdownX = ref(0); const dropdownY = ref(0); @@ -82,6 +85,15 @@ const dropdownOptionsFolder: DropdownOptionsType = [ ) }, + { + label: () => Cut, + key: 'cut', + icon: () => ( + + + + ) + }, { label: () => Delete, key: 'delete', @@ -102,6 +114,15 @@ const dropdownOptionsFile: DropdownOptionsType = [ ) }, + { + label: () => Cut, + key: 'cut', + icon: () => ( + + + + ) + }, { label: () => Delete, key: 'delete', @@ -124,6 +145,9 @@ const dropdownSelect = loadingMsgWrapper(message, async (key: string) => { await FS.download_file(token, dropdownCurrentNode.id); else createZipDialog([dropdownCurrentNode.id], dialog, jwt); break; + case 'cut': + cutNodes.value = [dropdownCurrentNode.id]; + break; case 'delete': dialog.warning({ title: 'Really delete?', @@ -269,19 +293,45 @@ const massDelete = loadingMsgWrapper(message, async () => { }); }); +function massCut() { + cutNodes.value = checkedRows.value; + checkedRows.value = []; +} + +const pasteNodes = loadingMsgWrapper(message, async () => { + const token = await check_token(jwt); + if (!token) return; + const res = await FS.move(token, cutNodes.value, props.currentNode.id); + cutNodes.value = []; + if (isErrorResponse(res)) { + message.error(`Failed to move nodes: ${res.message}`); + return; + } + emit('reloadNode'); +}); + const selectionCell = (): SummaryCell => { return { - value: - checkedRows.value.length != 0 ? ( - - Download - - Delete - - - ) : ( - '' - ), + value: ( + + {cutNodes.value.length != 0 ? ( + Paste + ) : ( + '' + )} + {checkedRows.value.length != 0 ? ( + <> + Download + Cut + + Delete + + + ) : ( + '' + )} + + ), colSpan: props.showPreview ? 2 : 1 }; };