feat: Add document download link component, refactor download URL resolution with expiration checks

This commit is contained in:
2025-12-04 23:38:17 +01:00
parent 22e39420bb
commit 86b9ac2ab6
8 changed files with 72 additions and 70 deletions
+7 -4
View File
@@ -8,15 +8,18 @@ import type { Document } from '../types/documents';
const asyncFalse = async () => false;
const resolveDocumentDownloadHref = (document?: Document | null): string | null => {
export const resolveDocumentDownloadHref = (document?: Document | null): string | null => {
if (!document) {
return null;
}
const downloadUrl = (document.current_version as { download?: { url: string } | null } | null)?.download?.url;
if (!downloadUrl) {
const download = document.current_version?.download;
if (!download?.url) {
return null;
}
return downloadUrl;
if (download.expires_at && download.expires_at <= Date.now()) {
return null;
}
return download.url;
};
const hasDocumentTextContentAsset = (document?: Document | null, getDocumentAsset?: GetDocumentAsset | null): boolean => {