Keep content on delete
This commit is contained in:
parent
715bbc4d2e
commit
961032b24f
1 changed files with 17 additions and 3 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
use anyhow::Context as _;
|
use anyhow::{Context as _, anyhow};
|
||||||
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, server_error},
|
errors::{SyncServerError, not_found_error, server_error},
|
||||||
utils::{normalize::normalize, sanitize_path::sanitize_path},
|
utils::{normalize::normalize, sanitize_path::sanitize_path},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -54,11 +54,25 @@ pub async fn delete_document(
|
||||||
.await
|
.await
|
||||||
.map_err(server_error)?;
|
.map_err(server_error)?;
|
||||||
|
|
||||||
|
let latest_version = state
|
||||||
|
.database
|
||||||
|
.get_latest_document(&vault_id, &document_id, Some(&mut transaction))
|
||||||
|
.await
|
||||||
|
.map_err(server_error)?
|
||||||
|
.map_or_else(
|
||||||
|
|| {
|
||||||
|
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: vec![],
|
content: latest_version.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