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
+21 -13
View File
@@ -46,11 +46,17 @@ struct DocumentVersionPayload {
id: Uuid,
version_number: i32,
size_bytes: i64,
download_path: String,
download: DownloadLinkPayload,
#[serde(default)]
assets: Vec<DocumentAssetInfo>,
}
#[derive(Deserialize)]
struct DownloadLinkPayload {
url: String,
expires_at: i64,
}
#[derive(Deserialize)]
struct DocumentVersionListItem {
id: Uuid,
@@ -67,8 +73,7 @@ struct DocumentAssetInfo {
#[derive(Deserialize)]
struct AssetProxyDetail {
id: Uuid,
url: Option<String>,
expires_at: Option<i64>,
download: Option<DownloadLinkPayload>,
}
#[derive(Deserialize)]
@@ -193,7 +198,8 @@ async fn upload_and_list_document() -> Result<()> {
.current_version
.as_ref()
.expect("current version detail");
assert!(current_version.download_path.starts_with("/api/download/"));
assert!(current_version.download.url.starts_with("/api/download/"));
assert!(current_version.download.expires_at > 0);
assert_eq!(current_version.version_number, 1);
assert_eq!(current_version.size_bytes, file_bytes.len() as i64);
assert!(current_version.assets.is_empty());
@@ -224,10 +230,11 @@ async fn upload_and_list_document() -> Result<()> {
.current_version
.as_ref()
.expect("list current version")
.download_path
.download
.url
.starts_with("/api/download/"));
let redirect = app.get(&current_version.download_path, None).await?;
let redirect = app.get(&current_version.download.url, None).await?;
assert_eq!(redirect.status(), StatusCode::TEMPORARY_REDIRECT);
let location = redirect
.headers()
@@ -343,12 +350,12 @@ async fn asset_detail_uses_proxy_urls_when_configured() -> Result<()> {
let body = body_to_vec(response.into_body()).await?;
let asset_detail: AssetProxyDetail = serde_json::from_slice(&body)?;
assert_eq!(asset_detail.id, asset_id);
let url = asset_detail
.url
.as_deref()
.ok_or_else(|| anyhow!("missing url"))?;
assert!(url.starts_with("/api/download/"));
assert!(asset_detail.expires_at.is_some());
let download = asset_detail
.download
.as_ref()
.ok_or_else(|| anyhow!("missing download link"))?;
assert!(download.url.starts_with("/api/download/"));
assert!(download.expires_at > 0);
app.cleanup().await?;
Ok(())
@@ -2055,7 +2062,8 @@ async fn list_document_versions_and_fetch_detail() -> Result<()> {
let detail_body = body_to_vec(detail_resp.into_body()).await?;
let version_detail: DocumentVersionPayload = serde_json::from_slice(&detail_body)?;
assert_eq!(version_detail.id, version_id);
assert!(version_detail.download_path.starts_with("/api/download/"));
assert!(version_detail.download.url.starts_with("/api/download/"));
assert!(version_detail.download.expires_at > 0);
assert!(version_detail.assets.is_empty());
app.cleanup().await?;