From 8275b940ac708452b6648f2441429878d5db95e2 Mon Sep 17 00:00:00 2001 From: xenofem Date: Sun, 1 May 2022 05:11:23 -0400 Subject: [PATCH] improve download code UI, tidy up URL structure --- src/main.rs | 18 ++++++++++------ static/index.html | 22 +++++++++++++------- static/states.css | 5 ++++- static/transbeam.css | 27 ++++++++++++++++-------- static/transbeam.js | 49 ++++++++++++++++++++++++++++++++++---------- 5 files changed, 87 insertions(+), 34 deletions(-) diff --git a/src/main.rs b/src/main.rs index 7aef76b..c5ba312 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,6 +10,7 @@ use actix_web::{ }; use actix_web_actors::ws; use log::error; +use serde::Deserialize; use store::FileStore; use tokio::sync::RwLock; @@ -17,20 +18,25 @@ const APP_NAME: &str = "transbeam"; type AppData = web::Data>; -#[get("/download/{file_code}")] +#[derive(Deserialize)] +struct DownloadRequest { + code: String, +} + +#[get("/download")] async fn handle_download( req: HttpRequest, - path: web::Path, + download: web::Query, data: AppData, ) -> actix_web::Result { - let file_code = path.into_inner(); - if !store::is_valid_storage_code(&file_code) { + let code = &download.code; + if !store::is_valid_storage_code(code) { return Ok(HttpResponse::NotFound().finish()); } let data = data.read().await; - let info = data.lookup_file(&file_code); + let info = data.lookup_file(code); if let Some(info) = info { - let storage_path = store::storage_dir().join(file_code); + let storage_path = store::storage_dir().join(code); let file = File::open(&storage_path)?; Ok(download::DownloadingFile { file, diff --git a/static/index.html b/static/index.html index d792bb1..f800d1c 100644 --- a/static/index.html +++ b/static/index.html @@ -16,9 +16,6 @@

transbeam

- - -
@@ -36,11 +33,11 @@
-