From 35960af854864d4554c217274527fb58087829e8 Mon Sep 17 00:00:00 2001 From: alemidev Date: Wed, 23 Mar 2022 02:43:56 +0100 Subject: [PATCH] add cause in errors, filesize to 50kb --- server/src/main.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/server/src/main.rs b/server/src/main.rs index 948320a..1138d6d 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -15,20 +15,22 @@ struct FileRequest { } #[derive(Display, Debug, Error)] -struct FileError {} +struct FileError { + cause: String, +} impl actix_web::error::ResponseError for FileError {} /// upload memo db async fn put(req: web::Json) -> Result { - if req.payload.len() < 20480 { - let fname = req.file.chars().filter(|c| c.is_alphanumeric()).collect::(); + if req.payload.len() < 51200 { + let fname = req.file.chars().filter(|c| c.is_alphanumeric()).collect::(); // TODO base64 uses some symbols! let f_res = web::block(||fs::File::create(fname)).await.unwrap(); - if f_res.is_err() { return Err(FileError{}); } + if f_res.is_err() { return Err(FileError{cause:"could not create file".to_string()}); } let mut f = f_res.unwrap(); let _res = web::block(move || f.write(base64::decode(&req.payload).unwrap().as_slice())).await.unwrap(); return Ok("OK".to_string()); } else { - return Err(FileError{}); + return Err(FileError{cause:"size too big".to_string()}); } } @@ -48,7 +50,7 @@ async fn get(req: web::Json) -> Result { Err(e) => println!("[!] could not list dirs : {}", e.to_string()), } } - return Err(FileError{}); + return Err(FileError{cause:"not found".to_string()}); } #[actix_web::main]