Allow deleting non-existent files
This commit is contained in:
parent
3fe70b37ec
commit
0295b5633f
1 changed files with 5 additions and 12 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
use anyhow::{Context as _, anyhow};
|
use anyhow::Context as _;
|
||||||
use axum::{
|
use axum::{
|
||||||
Extension,
|
Extension,
|
||||||
extract::{Path, State},
|
extract::{Path, State},
|
||||||
|
|
@ -18,7 +18,7 @@ use crate::{
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
config::user_config::User,
|
config::user_config::User,
|
||||||
errors::{SyncServerError, not_found_error, server_error},
|
errors::{SyncServerError, server_error},
|
||||||
utils::{normalize::normalize, sanitize_path::sanitize_path},
|
utils::{normalize::normalize, sanitize_path::sanitize_path},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -54,25 +54,18 @@ pub async fn delete_document(
|
||||||
.await
|
.await
|
||||||
.map_err(server_error)?;
|
.map_err(server_error)?;
|
||||||
|
|
||||||
let latest_version = state
|
let latest_content = state
|
||||||
.database
|
.database
|
||||||
.get_latest_document(&vault_id, &document_id, Some(&mut transaction))
|
.get_latest_document(&vault_id, &document_id, Some(&mut transaction))
|
||||||
.await
|
.await
|
||||||
.map_err(server_error)?
|
.map_err(server_error)?
|
||||||
.map_or_else(
|
.map_or_else(Vec::new, |version| version.content); // in case the document has never existed before deleting it
|
||||||
|| {
|
|
||||||
Err(not_found_error(anyhow!(
|
|
||||||
"Document with id `{document_id}` not found",
|
|
||||||
)))
|
|
||||||
},
|
|
||||||
Ok,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
let new_version = StoredDocumentVersion {
|
let new_version = StoredDocumentVersion {
|
||||||
vault_update_id: last_update_id + 1,
|
vault_update_id: last_update_id + 1,
|
||||||
document_id,
|
document_id,
|
||||||
relative_path: sanitize_path(&request.relative_path),
|
relative_path: sanitize_path(&request.relative_path),
|
||||||
content: latest_version.content, // copy the content from the latest version
|
content: latest_content, // copy the content from the latest version
|
||||||
updated_date: chrono::Utc::now(),
|
updated_date: chrono::Utc::now(),
|
||||||
is_deleted: true,
|
is_deleted: true,
|
||||||
user_id: user.name,
|
user_id: user.name,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue