feat: Add document download link component, refactor download URL resolution with expiration checks
This commit is contained in:
@@ -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 => {
|
||||
|
||||
Reference in New Issue
Block a user