/api/download

This commit is contained in:
2025-11-11 02:19:39 +01:00
parent 425e03650f
commit ac9e688e7a
10 changed files with 116 additions and 29 deletions
+26 -12
View File
@@ -964,7 +964,7 @@ impl<'a> DocumentsService<'a> {
error!(error = ?err, "failed to issue asset download token");
AppError::internal("failed to issue asset download token")
})?;
(format!("/download/{token}"), None)
(format!("/api/download/{token}"), None)
} else {
let storage = storage
.as_ref()
@@ -1044,19 +1044,33 @@ impl<'a> DocumentsService<'a> {
tenant_id: Uuid,
document_id: Uuid,
) -> AppResult<()> {
let now = Utc::now().naive_utc();
diesel::update(
documents::table
conn.transaction::<_, AppError, _>(|conn| {
let document: Document = documents::table
.find(document_id)
.filter(documents::tenant_id.eq(tenant_id)),
)
.set((
documents::deleted_at.eq(Some(now)),
documents::updated_at.eq(now),
))
.execute(conn)?;
.filter(documents::tenant_id.eq(tenant_id))
.for_update()
.first(conn)
.optional()?
.ok_or_else(AppError::not_found)?;
Ok(())
if document.deleted_at.is_some() {
return Err(AppError::conflict("document already trashed"));
}
let now = Utc::now().naive_utc();
diesel::update(
documents::table
.find(document_id)
.filter(documents::tenant_id.eq(tenant_id)),
)
.set((
documents::deleted_at.eq(Some(now)),
documents::updated_at.eq(now),
))
.execute(conn)?;
Ok(())
})
}
pub fn delete_document(