26 lines
870 B
TypeScript
26 lines
870 B
TypeScript
export type DocLike = { uuid: string; original_name?: string; name?: string; extension?: string; mime_type?: string }
|
|
|
|
const PREVIEW_EXTS = ['pdf', 'txt', 'jpeg', 'jpg', 'png', 'doc', 'docx']
|
|
const DOWNLOAD_ONLY_EXTS = ['xls', 'xlsx', 'csv']
|
|
|
|
export function getExtension(doc: DocLike): string {
|
|
const ext = doc.extension || (doc.original_name || doc.name || '').split('.').pop() || ''
|
|
return ext.toLowerCase()
|
|
}
|
|
|
|
export function isPreviewableExt(ext?: string): boolean {
|
|
if (!ext) return false
|
|
return PREVIEW_EXTS.includes(ext.toLowerCase())
|
|
}
|
|
|
|
export function isDownloadOnlyExt(ext?: string): boolean {
|
|
if (!ext) return false
|
|
return DOWNLOAD_ONLY_EXTS.includes(ext.toLowerCase())
|
|
}
|
|
|
|
export function classifyDocument(doc: DocLike): 'preview' | 'download' {
|
|
const ext = getExtension(doc)
|
|
if (isPreviewableExt(ext)) return 'preview'
|
|
return 'download'
|
|
}
|