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]