Files
Inventory_frontend/app/utils/documentPreview.js
2025-09-17 17:12:41 +02:00

26 lines
945 B
JavaScript

import { getFileIcon } from './fileIcons'
export const getPreviewType = (document) => {
if (!document) return null
const mime = (document.mimeType || '').toLowerCase()
const path = document.path || ''
const check = (prefix) => mime.startsWith(prefix) || path.startsWith(`data:${prefix}`)
if (check('image/')) return 'image'
if (mime === 'application/pdf' || path.startsWith('data:application/pdf')) return 'pdf'
if (check('audio/')) return 'audio'
if (check('video/')) return 'video'
if (check('text/') || mime.includes('json') || mime.includes('xml') || path.startsWith('data:application/json')) return 'text'
return null
}
export const canPreviewDocument = (document = {}) => !!getPreviewType(document)
export const describeDocument = (document) => {
if (!document) return ''
const name = document.filename || document.name || ''
const icon = getFileIcon({ name, mime: document.mimeType })
return icon.label
}