DownloadLink
This commit is contained in:
@@ -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(¤t_version.download_path, None).await?;
|
||||
let redirect = app.get(¤t_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?;
|
||||
|
||||
@@ -15,7 +15,13 @@ struct DocumentInfo {
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct DocumentVersion {
|
||||
download_path: String,
|
||||
download: DownloadLink,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct DownloadLink {
|
||||
url: String,
|
||||
expires_at: i64,
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -46,7 +52,8 @@ async fn document_download_redirects_when_proxy_disabled() -> Result<()> {
|
||||
.current_version
|
||||
.as_ref()
|
||||
.expect("missing version")
|
||||
.download_path
|
||||
.download
|
||||
.url
|
||||
.clone();
|
||||
|
||||
let redirect = app.get(&download_path, None).await?;
|
||||
|
||||
Reference in New Issue
Block a user