Added error handling for download functions to avoid race conditions
This commit is contained in:
parent
aa2db48a68
commit
c687058a06
@ -461,14 +461,15 @@ pub fn download(span: &Span, req: &mut Request, db: &mut DBConnection) -> Result
|
|||||||
AppError::BadRequest("Unknown node").err()
|
AppError::BadRequest("Unknown node").err()
|
||||||
} else {
|
} else {
|
||||||
let file_name = format!("./temp/{}", entry.temp_id);
|
let file_name = format!("./temp/{}", entry.temp_id);
|
||||||
let resp = Response::from_file(File::open(std::path::Path::new(&file_name)).unwrap())
|
Ok(Response::from_file(
|
||||||
.with_header(header("content-type", "application/zip"))
|
File::open(std::path::Path::new(&file_name)).map_err(|_| AppError::BadRequest("Unknown file"))?
|
||||||
.with_header(header(
|
)
|
||||||
"content-disposition",
|
.with_header(header("content-type", "application/zip"))
|
||||||
&("attachment; filename=".to_owned() + &node.name + ".zip")
|
.with_header(header(
|
||||||
))
|
"content-disposition",
|
||||||
.boxed();
|
&("attachment; filename=".to_owned() + &node.name + ".zip")
|
||||||
Ok(resp)
|
))
|
||||||
|
.boxed())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -527,7 +528,9 @@ pub fn download_preview(
|
|||||||
get_reply(&dto::responses::DownloadBase64 {
|
get_reply(&dto::responses::DownloadBase64 {
|
||||||
statusCode: 200,
|
statusCode: 200,
|
||||||
data: "data:image/png;base64,".to_owned()
|
data: "data:image/png;base64,".to_owned()
|
||||||
+ &base64::encode(std::fs::read(std::path::Path::new(&file)).unwrap())
|
+ &base64::encode(
|
||||||
|
std::fs::read(std::path::Path::new(&file)).map_err(|_| AppError::BadRequest("Unknown file"))?
|
||||||
|
)
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
AppError::BadRequest("No preview").err()
|
AppError::BadRequest("No preview").err()
|
||||||
|
Loading…
Reference in New Issue
Block a user