From 412494edf618b8eda71656855656f9b8b21c3eae Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Tue, 13 Sep 2022 15:10:04 +0200 Subject: Delete an uploaded file --- src/errors.rs | 7 +++++++ src/files.rs | 7 +++++++ 2 files changed, 14 insertions(+) (limited to 'src') diff --git a/src/errors.rs b/src/errors.rs index e6f8e2c..15ca9d4 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -68,3 +68,10 @@ impl From for AppError { AppError::BadRequest(error) } } + +/// Raise a generic io error +impl From for AppError { + fn from(error: std::io::Error) -> Self { + AppError::BadRequest(error.to_string()) + } +} diff --git a/src/files.rs b/src/files.rs index 0bc531d..16a11b6 100644 --- a/src/files.rs +++ b/src/files.rs @@ -55,6 +55,13 @@ pub async fn upload( )) } +/// Delete a file from the filesystem +pub async fn delete_upload(filename: String) -> Result<(), AppError> { + fs::remove_file(filename)?; + + Ok(()) +} + /// Axum endpoint which shows uploaded file pub async fn show_uploads(Path(id): Path) -> (HeaderMap, Vec) { let index = id.find('.').unwrap_or(usize::max_value()); -- cgit v1.2.3-71-g8e6c