improve download code UI, tidy up URL structure

This commit is contained in:
xenofem 2022-05-01 05:11:23 -04:00
parent 86bdac20af
commit 8275b940ac
5 changed files with 87 additions and 34 deletions

View file

@ -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<RwLock<FileStore>>;
#[get("/download/{file_code}")]
#[derive(Deserialize)]
struct DownloadRequest {
code: String,
}
#[get("/download")]
async fn handle_download(
req: HttpRequest,
path: web::Path<String>,
download: web::Query<DownloadRequest>,
data: AppData,
) -> actix_web::Result<HttpResponse> {
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,