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