Can delete an uploaded file
This commit is contained in:
parent
7c04acaf4b
commit
91d8b1a579
@ -58,3 +58,15 @@ pub async fn serve_file(req: HttpRequest, file: &File) -> HttpResult {
|
|||||||
))
|
))
|
||||||
.body(files_service::get_file_content(file).await?))
|
.body(files_service::get_file_content(file).await?))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Delete an uploaded file
|
||||||
|
pub async fn delete(file_extractor: FileIdExtractor) -> HttpResult {
|
||||||
|
match files_service::delete_file_if_unused(file_extractor.as_ref().id()).await {
|
||||||
|
Ok(true) => Ok(HttpResponse::Accepted().finish()),
|
||||||
|
Ok(false) => Ok(HttpResponse::Conflict().finish()),
|
||||||
|
Err(e) => {
|
||||||
|
log::error!("Failed to delete file: {e}");
|
||||||
|
Ok(HttpResponse::InternalServerError().finish())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -125,7 +125,10 @@ async fn main() -> std::io::Result<()> {
|
|||||||
"/api/file/{file_id}",
|
"/api/file/{file_id}",
|
||||||
web::get().to(files_controller::download),
|
web::get().to(files_controller::download),
|
||||||
)
|
)
|
||||||
// TODO Delete file
|
.route(
|
||||||
|
"/api/file/{file_id}",
|
||||||
|
web::delete().to(files_controller::delete),
|
||||||
|
)
|
||||||
// Static assets
|
// Static assets
|
||||||
.route("/", web::get().to(static_controller::root_index))
|
.route("/", web::get().to(static_controller::root_index))
|
||||||
.route(
|
.route(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user