download url

This commit is contained in:
2025-11-22 00:28:11 +01:00
parent dd7dae5f9d
commit c50372af06
6 changed files with 35 additions and 51 deletions
+8 -10
View File
@@ -40,7 +40,6 @@ interface UseDocumentPreviewArgs {
};
selectedFolder?: FolderId | null;
api: ApiClient;
resolveApiPath?: (path: string) => string;
notifyApiError: (error: unknown, message: string) => void;
navigate: NavigateHandler;
locationPathname: string;
@@ -67,7 +66,6 @@ const useDocumentPreview = ({
documentsManager,
selectedFolder,
api,
resolveApiPath,
notifyApiError,
navigate,
locationPathname,
@@ -109,7 +107,7 @@ const useDocumentPreview = ({
async (documentId: DocumentId, { force = false }: { force?: boolean } = {}): Promise<DocumentLink | null> => {
if (!documentId) return null;
const existing = documentLinks.get(documentId) || null;
const existing = documentLinks.get(documentId);
const now = Date.now();
const expiresAt = Number.isFinite(existing?.expiresAt) ? Number(existing?.expiresAt) : null;
if (!force && existing && (!expiresAt || expiresAt > now)) {
@@ -123,17 +121,17 @@ const useDocumentPreview = ({
const request: Promise<DocumentLink | null> = (async () => {
try {
const docResponse = await api.get<{ document?: Record<string, any> }>(`/documents/${documentId}`);
const downloadPath = docResponse.data?.document?.current_version?.download_path;
if (!downloadPath || !resolveApiPath) {
throw new Error('Document missing download path');
const download = docResponse.data?.document?.current_version?.download || null;
const downloadUrl = download?.url;
if (!downloadUrl) {
throw new Error('Document missing download url');
}
const href = resolveApiPath(downloadPath);
const entry: DocumentLink = {
url: href,
url: downloadUrl,
contentType: docResponse.data?.document?.current_version?.version?.content_type || null,
filename: docResponse.data?.document?.filename,
expiresAt: Date.now() + 5 * 60 * 1000,
expiresAt: download?.expires_at,
};
setDocumentLinks((prev) => {
const next = new Map(prev);
@@ -152,7 +150,7 @@ const useDocumentPreview = ({
previewInflightRef.current.set(documentId, request);
return request;
},
[documentLinks, api, resolveApiPath, notifyApiError],
[documentLinks, api, notifyApiError],
);
const ensurePreviewData = useCallback(