DownloadLink

This commit is contained in:
2025-11-21 13:53:13 +01:00
parent bd55b784d7
commit 5871c7ae6e
6 changed files with 262 additions and 68 deletions
+80 -1
View File
@@ -17,7 +17,7 @@ use uuid::Uuid;
use crate::auth::{ensure_active_tenant_with_conn, jwt::DownloadSubject, TenantScopedConn};
use crate::documents::asset::{
asset_disposition, DocumentAssetDetailResponse, DocumentAssetResponse,
DocumentVersionDetailResponse, DocumentVersionResponse,
DocumentVersionDetailResponse, DocumentVersionResponse, DownloadLink,
};
#[allow(unused_imports)]
use crate::error::ApiErrorResponse;
@@ -492,6 +492,81 @@ pub async fn get_document_asset(
ok_json(detail)
}
#[utoipa::path(
post,
path = "/api/documents/{id}/download",
params(("id" = Uuid, Path, description = "Document ID")),
responses((status = 200, description = "Download link for current version", body = DownloadLink)),
tag = "Documents"
)]
pub async fn refresh_document_download(
State(state): State<AppState>,
Path(document_id): Path<Uuid>,
TenantScopedConn {
mut conn,
tenant_id,
user_id,
..
}: TenantScopedConn,
) -> AppResult<JsonResponse<DownloadLink>> {
let service = DocumentsService::new(&state);
let link = service
.get_document_download_link(&mut conn, tenant_id, user_id, document_id)
.await?;
ok_json(link)
}
#[utoipa::path(
post,
path = "/api/documents/{id}/versions/{version_id}/download",
params(
("id" = Uuid, Path, description = "Document ID"),
("version_id" = Uuid, Path, description = "Version ID")
),
responses((status = 200, description = "Download link for version", body = DownloadLink)),
tag = "Documents"
)]
pub async fn refresh_document_version_download(
State(state): State<AppState>,
Path((document_id, version_id)): Path<(Uuid, Uuid)>,
TenantScopedConn {
mut conn,
tenant_id,
user_id,
..
}: TenantScopedConn,
) -> AppResult<JsonResponse<DownloadLink>> {
let service = DocumentsService::new(&state);
let link = service
.get_document_version_download_link(&mut conn, tenant_id, user_id, document_id, version_id)
.await?;
ok_json(link)
}
#[utoipa::path(
post,
path = "/api/assets/{asset_id}/download",
params(("asset_id" = Uuid, Path, description = "Asset ID")),
responses((status = 200, description = "Asset download link", body = DownloadLink)),
tag = "Assets"
)]
pub async fn refresh_asset_download(
State(state): State<AppState>,
Path(asset_id): Path<Uuid>,
TenantScopedConn {
mut conn,
tenant_id,
user_id,
..
}: TenantScopedConn,
) -> AppResult<JsonResponse<DownloadLink>> {
let service = DocumentsService::new(&state);
let link = service
.get_asset_download_link(&mut conn, tenant_id, user_id, asset_id)
.await?;
ok_json(link)
}
#[utoipa::path(
get,
path = "/api/documents/{id}/versions",
@@ -1017,6 +1092,7 @@ pub async fn remove_tag(
crate::routes::documents::check_document,
crate::routes::documents::upload_document,
crate::routes::documents::get_document,
crate::routes::documents::refresh_document_download,
crate::routes::documents::update_document,
crate::routes::documents::trash_document,
crate::routes::documents::delete_document,
@@ -1036,6 +1112,8 @@ pub async fn remove_tag(
crate::routes::documents::get_document_asset,
crate::routes::documents::list_document_versions,
crate::routes::documents::get_document_version,
crate::routes::documents::refresh_document_version_download,
crate::routes::documents::refresh_asset_download,
),
components(schemas(
crate::services::documents::DocumentListQuery,
@@ -1066,6 +1144,7 @@ pub async fn remove_tag(
crate::documents::asset::DocumentVersionDetailResponse,
crate::documents::asset::DocumentAssetResponse,
crate::documents::asset::DocumentAssetDetailResponse,
crate::documents::asset::DownloadLink,
crate::documents::correspondents::DocumentCorrespondentResponse,
crate::error::ApiErrorResponse,
))
+25 -6
View File
@@ -130,6 +130,12 @@ pub fn create_router(state: AppState) -> Router<()> {
ApiCapability::DocumentsRead,
])),
)
.route(
"/{id}/download",
post(documents::refresh_document_download).layer(RequireCapabilitiesLayer::all([
ApiCapability::DocumentsRead,
])),
)
.route(
"/{id}/trash",
post(documents::trash_document).layer(RequireCapabilitiesLayer::all([
@@ -178,6 +184,12 @@ pub fn create_router(state: AppState) -> Router<()> {
ApiCapability::DocumentsRead,
])),
)
.route(
"/{id}/versions/{version_id}/download",
post(documents::refresh_document_version_download).layer(
RequireCapabilitiesLayer::all([ApiCapability::DocumentsRead]),
),
)
.route(
"/{id}/restore",
post(documents::restore_document).layer(RequireCapabilitiesLayer::all([
@@ -366,12 +378,19 @@ pub fn create_router(state: AppState) -> Router<()> {
);
let protected_state = state.clone();
let assets_routes = Router::new().route(
"/{asset_id}",
get(documents::get_document_asset).layer(RequireCapabilitiesLayer::all([
ApiCapability::DocumentsRead,
])),
);
let assets_routes = Router::new()
.route(
"/{asset_id}",
get(documents::get_document_asset).layer(RequireCapabilitiesLayer::all([
ApiCapability::DocumentsRead,
])),
)
.route(
"/{asset_id}/download",
post(documents::refresh_asset_download).layer(RequireCapabilitiesLayer::all([
ApiCapability::DocumentsRead,
])),
);
let manage_tenants_layer = RequireCapabilitiesLayer::all([ApiCapability::TenantsWrite]);
let tenants_routes = Router::new()