/api/download
This commit is contained in:
@@ -83,7 +83,7 @@ pub fn build_download_path(
|
||||
state
|
||||
.jwt
|
||||
.generate_download_token(document.id, version_id, user_id, document.tenant_id)
|
||||
.map(|token| format!("/download/{token}"))
|
||||
.map(|token| format!("/api/download/{token}"))
|
||||
.map_err(|err| {
|
||||
tracing::error!(error = ?err, "failed to generate download token");
|
||||
AppError::internal("failed to generate download token")
|
||||
|
||||
@@ -558,7 +558,7 @@ pub async fn get_document_version(
|
||||
|
||||
#[utoipa::path(
|
||||
get,
|
||||
path = "/download/{token}",
|
||||
path = "/api/download/{token}",
|
||||
params(("token" = String, Path, description = "Download token")),
|
||||
responses((status = 200, description = "Proxied download stream or redirect")),
|
||||
tag = "Documents"
|
||||
|
||||
@@ -210,7 +210,7 @@ pub fn create_router(state: AppState) -> Router<()> {
|
||||
);
|
||||
|
||||
let download_routes =
|
||||
Router::new().route("/download/{token}", get(documents::download_with_token));
|
||||
Router::new().route("/api/download/{token}", get(documents::download_with_token));
|
||||
|
||||
let folders_routes = Router::new()
|
||||
.route(
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -24,9 +24,7 @@ use crate::{
|
||||
|
||||
use super::{
|
||||
analyze::determine_thumbnail_support,
|
||||
taskflow::{
|
||||
document::DocumentVersionTaskContext, Task, TaskContext, TaskError, TaskResult,
|
||||
},
|
||||
taskflow::{document::DocumentVersionTaskContext, Task, TaskContext, TaskError, TaskResult},
|
||||
};
|
||||
|
||||
pub const THUMBNAIL_WIDTH: u32 = 512;
|
||||
|
||||
Reference in New Issue
Block a user