From 530218a4b83ca822fda0c5cec2132df3a2245320 Mon Sep 17 00:00:00 2001 From: Nils Schneider Date: Sat, 22 Nov 2025 14:43:05 +0100 Subject: [PATCH] mimetype --- frontend/src/app/useDocumentPreview.ts | 4 ++-- frontend/src/desktop/DesktopWorkspace.tsx | 10 ++++----- frontend/src/detail/PreviewZoomOverlay.tsx | 6 ++--- frontend/src/documents/documentSummary.ts | 6 ++--- .../documents/hooks/useDocumentsPanelProps.ts | 2 +- .../src/documents/panel/DocumentsPanel.tsx | 10 ++++----- frontend/src/lib/apiTypes.ts | 4 ++-- frontend/src/preview/DocumentViewerLayout.tsx | 22 +++++++++---------- frontend/src/preview/DocumentViewerPanel.tsx | 14 ++++++------ 9 files changed, 38 insertions(+), 40 deletions(-) diff --git a/frontend/src/app/useDocumentPreview.ts b/frontend/src/app/useDocumentPreview.ts index 5b93709..b1655a4 100644 --- a/frontend/src/app/useDocumentPreview.ts +++ b/frontend/src/app/useDocumentPreview.ts @@ -19,7 +19,7 @@ type DocumentLike = { type DocumentLink = { url?: string; - contentType?: string | null; + mimeType?: string | null; filename?: string | null; expiresAt?: number; }; @@ -124,7 +124,7 @@ const useDocumentPreview = ({ const entry: DocumentLink = { url: downloadUrl, - contentType: docResponse?.content_type || null, + mimeType: docResponse?.mime_type || null, filename: docResponse?.filename, expiresAt: download?.expires_at, }; diff --git a/frontend/src/desktop/DesktopWorkspace.tsx b/frontend/src/desktop/DesktopWorkspace.tsx index 3f95414..1cd0fed 100644 --- a/frontend/src/desktop/DesktopWorkspace.tsx +++ b/frontend/src/desktop/DesktopWorkspace.tsx @@ -32,8 +32,8 @@ import '../styles/workspace/workspace-cards.css'; type Identifier = string | number; type TagLike = { id?: Identifier | null; label?: string; color?: string | null } | null; -type DocumentLinkLike = { url?: string | null; contentType?: string | null }; -type OverlaySource = { url: string; alt?: string | null; contentType?: string | null }; +type DocumentLinkLike = { url?: string | null; mimeType?: string | null }; +type OverlaySource = { url: string; alt?: string | null; mimeType?: string | null }; export interface DeskDocument { id?: Identifier | null; @@ -68,7 +68,7 @@ interface OverlayOriginTransform { interface OverlayDisplay { url: string; alt?: string | null; - contentType?: string | null; + mimeType?: string | null; } interface DocumentSizeInfo { @@ -565,7 +565,7 @@ const DesktopWorkspace: React.FC = ({ }; } - const docContentType = doc?.content_type ?? null; + const docMimeType = doc?.mime_type ?? null; const applyEntry = (entry?: DocumentLinkLike | null) => { if (!entry?.url) { @@ -575,7 +575,7 @@ const DesktopWorkspace: React.FC = ({ setOverlaySource({ url: entry.url, alt: doc.title, - contentType: docContentType || undefined, + mimeType: docMimeType || undefined, }); }; diff --git a/frontend/src/detail/PreviewZoomOverlay.tsx b/frontend/src/detail/PreviewZoomOverlay.tsx index 010b3be..e095ca4 100644 --- a/frontend/src/detail/PreviewZoomOverlay.tsx +++ b/frontend/src/detail/PreviewZoomOverlay.tsx @@ -6,7 +6,7 @@ import PdfViewer from '../preview/PdfViewer'; type DocumentLike = { id?: string | number; title?: string; - content_type?: string | null; + mime_type?: string | null; [key: string]: unknown; }; @@ -23,13 +23,13 @@ type DisplayKind = 'image' | 'pdf'; type DocumentLink = { url: string; alt?: string; - contentType?: string | null; + mimeType?: string | null; }; type DocumentLikeWithPreview = DocumentLike & { documentLink?: DocumentLink }; const determineDisplayKind = (entry?: DocumentLink | null): DisplayKind => { - const type = entry?.contentType?.toLowerCase?.() || ''; + const type = entry?.mimeType?.toLowerCase?.() || ''; if (type.includes('pdf')) { return 'pdf'; } diff --git a/frontend/src/documents/documentSummary.ts b/frontend/src/documents/documentSummary.ts index eac86d8..e883a64 100644 --- a/frontend/src/documents/documentSummary.ts +++ b/frontend/src/documents/documentSummary.ts @@ -24,7 +24,7 @@ export interface SummaryDocument { title?: string | null; original_name?: string | null; filename?: string | null; - content_type?: string | null; + mime_type?: string | null; folder_id?: string | null; folder_name?: string; current_version?: DocumentVersion | null; @@ -72,7 +72,7 @@ export interface MetadataDocumentLike { updated_at?: string | null; filename?: string | null; original_name?: string | null; - content_type?: string | null; + mime_type?: string | null; metadata?: DocumentMetadataPayload | null; current_version?: { checksum?: string | null } | null; } @@ -105,7 +105,7 @@ export const describeDocumentSummary = (document?: SummaryDocument | null, optio { key: 'updated', label: 'Updated at', value: formatDateLabel(doc.updated_at) }, { key: 'folder', label: 'Folder', value: folderLabel, kind: 'folder' }, { key: 'size', label: 'Size', value: sizeLabel }, - { key: 'content-type', label: 'Content type', value: doc.content_type || 'Unknown' }, + { key: 'mime-type', label: 'MIME type', value: doc.mime_type || 'Unknown' }, { key: 'pages', label: 'Pages', value: pageCountLabel }, { key: 'filename', label: 'Filename', value: doc.filename }, { key: 'original-filename', label: 'Original filename', value: doc.original_name }, diff --git a/frontend/src/documents/hooks/useDocumentsPanelProps.ts b/frontend/src/documents/hooks/useDocumentsPanelProps.ts index 7c687bd..224ee3c 100644 --- a/frontend/src/documents/hooks/useDocumentsPanelProps.ts +++ b/frontend/src/documents/hooks/useDocumentsPanelProps.ts @@ -5,7 +5,7 @@ type Identifier = string | number; interface DocumentLinkLike { url?: string | null; - contentType?: string | null; + mimeType?: string | null; } export interface Breadcrumb { diff --git a/frontend/src/documents/panel/DocumentsPanel.tsx b/frontend/src/documents/panel/DocumentsPanel.tsx index 33a3b08..643dcac 100644 --- a/frontend/src/documents/panel/DocumentsPanel.tsx +++ b/frontend/src/documents/panel/DocumentsPanel.tsx @@ -38,7 +38,7 @@ interface DocumentsPanelProps extends DocumentsPanelInnerProps { const defaultGetDocumentAsset = (_doc?: unknown, _type?: string) => null; -export type DocumentLinkLike = { url?: string | null; contentType?: string | null }; +export type DocumentLinkLike = { url?: string | null; mimeType?: string | null }; const DocumentsPanelInner: React.FC = ({ headerLeading = null, @@ -257,7 +257,7 @@ const DocumentsPanelInner: React.FC = ({ const isDeskView = viewMode === 'desk'; type Identifier = string | number; - type ZoomSource = { url: string; alt?: string | null; contentType?: string | null }; +type ZoomSource = { url: string; alt?: string | null; mimeType?: string | null }; const [previewDocId, setPreviewDocId] = useState(null); @@ -290,9 +290,7 @@ const DocumentsPanelInner: React.FC = ({ cancelled = true; }; } - const docContentType = previewDoc.content_type; - const versionContentType = previewDoc.current_version?.content_type; - const contentFallback = docContentType || versionContentType || null; + const documentMimeType = previewDoc.mime_type; const applyEntry = (entry?: DocumentLinkLike | null) => { if (!entry?.url) { @@ -302,7 +300,7 @@ const DocumentsPanelInner: React.FC = ({ setPreviewZoomSource({ url: entry.url, alt: previewDoc.title, - contentType: entry.contentType || contentFallback || undefined, + mimeType: documentMimeType, }); }; diff --git a/frontend/src/lib/apiTypes.ts b/frontend/src/lib/apiTypes.ts index fb2b089..430919a 100644 --- a/frontend/src/lib/apiTypes.ts +++ b/frontend/src/lib/apiTypes.ts @@ -33,7 +33,7 @@ export interface DocumentVersionResponse { size_bytes: number; checksum: string; created_at: string; - content_type: string | null; + mime_type?: string | null; metadata: Record; download: DownloadLink; assets?: AssetResponse[] | null; @@ -44,7 +44,7 @@ export interface DocumentResponse { filename: string; title: string; original_name: string; - content_type?: string | null; + mime_type?: string | null; folder_id?: string | null; created_at: string; updated_at: string; diff --git a/frontend/src/preview/DocumentViewerLayout.tsx b/frontend/src/preview/DocumentViewerLayout.tsx index 2b86e18..b23f133 100644 --- a/frontend/src/preview/DocumentViewerLayout.tsx +++ b/frontend/src/preview/DocumentViewerLayout.tsx @@ -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 (
- Preview is not available for {displayContentType} files. + Preview is not available for {displayMimeType} files.
{displayFilename}
; 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 = ({ 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 = ({ 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]);