This commit is contained in:
2025-11-22 14:43:05 +01:00
parent 5498cf4342
commit 530218a4b8
9 changed files with 38 additions and 40 deletions
+11 -11
View File
@@ -7,7 +7,7 @@ import PdfViewer from './PdfViewer';
interface DocumentLike {
id?: string | number;
title?: string;
content_type?: string;
mime_type?: string;
filename?: string;
original_name?: string;
[key: string]: unknown;
@@ -15,7 +15,7 @@ interface DocumentLike {
interface DocumentLink {
url?: string;
contentType?: string;
mimeType?: string;
filename?: string;
}
@@ -100,8 +100,8 @@ const DocumentViewerLayout = ({
return null;
}
const normalizedContentType = (documentLink.contentType
|| document.content_type
const normalizedMimeType = (documentLink.mimeType
|| document.mime_type
|| '')
.toLowerCase();
const normalizedFilename = documentLink.filename
@@ -109,12 +109,12 @@ const DocumentViewerLayout = ({
|| document.original_name
|| '';
const fileExtension = getFileExtension(normalizedFilename);
const isImage = normalizedContentType.startsWith('image/');
const isPdf = normalizedContentType === 'application/pdf'
|| normalizedContentType === 'application/x-pdf';
const isAudio = normalizedContentType.startsWith('audio/')
const isImage = normalizedMimeType.startsWith('image/');
const isPdf = normalizedMimeType === 'application/pdf'
|| normalizedMimeType === 'application/x-pdf';
const isAudio = normalizedMimeType.startsWith('audio/')
|| AUDIO_EXTENSIONS.has(fileExtension);
const isVideo = normalizedContentType.startsWith('video/')
const isVideo = normalizedMimeType.startsWith('video/')
|| VIDEO_EXTENSIONS.has(fileExtension);
const mediaLabel = document.title
|| normalizedFilename
@@ -170,7 +170,7 @@ const DocumentViewerLayout = ({
);
}
const displayContentType = document.content_type || documentLink.contentType || 'this file type';
const displayMimeType = document.mime_type || documentLink.mimeType || 'this file type';
const displayFilename = documentLink.filename
|| document.filename
|| document.original_name
@@ -179,7 +179,7 @@ const DocumentViewerLayout = ({
return (
<div className="document-viewer__unsupported">
<div className="document-viewer__unsupported-message">
Preview is not available for {displayContentType} files.
Preview is not available for {displayMimeType} files.
</div>
<div className="document-viewer__unsupported-filename">{displayFilename}</div>
<a
+7 -7
View File
@@ -32,20 +32,20 @@ import { usePanelResizeBindings } from '../app/PanelManagerContext';
interface DocumentLike {
id?: string | number;
title?: string;
content_type?: string | null;
mime_type?: string | null;
issued_at?: string | null;
folder_id?: string | null;
correspondents?: Array<{ id?: string | number; name?: string }>;
current_version?: {
version_number?: number;
download?: { url?: string | null; expires_at?: number } | null;
version?: { content_type?: string | null } | null;
mime_type?: string | null;
filename?: string | null;
} | null;
documentLink?: {
url: string;
alt?: string;
contentType?: string | null;
mimeType?: string | null;
} | null;
[key: string]: unknown;
}
@@ -268,11 +268,11 @@ const DocumentViewerPanel: React.FC<DocumentViewerPanelProps> = ({
if (!href) {
return null;
}
const contentType = document.content_type || null;
const mimeType = document.mime_type;
const filename = document.current_version?.filename || document.filename || document.title || null;
return {
url: href,
contentType,
mimeType,
filename,
};
}, [document, resolveApiPath]);
@@ -363,11 +363,11 @@ const DocumentViewerPanel: React.FC<DocumentViewerPanelProps> = ({
if (!resolvedDocumentLink?.url || !document) {
return null;
}
const normalizedContentType = document.content_type || null;
const normalizedMimeType = document.mime_type;
return {
url: resolvedDocumentLink.url,
alt: document.title,
contentType: normalizedContentType || undefined,
mimeType: normalizedMimeType,
};
}, [document, resolvedDocumentLink?.url]);