feat: add document preview overlay
This commit is contained in:
25
app/utils/documentPreview.js
Normal file
25
app/utils/documentPreview.js
Normal file
@@ -0,0 +1,25 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user