29 lines
836 B
TypeScript
29 lines
836 B
TypeScript
import { downloadAttachmentFile } from '@/utils/download-attachment'
|
|
|
|
const minioBaseUrl = (import.meta.env.VITE_MINIO_BASE_URL || '').replace(/\/$/, '')
|
|
|
|
export function attachmentFullUrl(url: string) {
|
|
const u = String(url || '').trim()
|
|
if (!u) return ''
|
|
if (/^https?:\/\//i.test(u)) return u
|
|
return minioBaseUrl ? `${minioBaseUrl}/${u.replace(/^\//, '')}` : u
|
|
}
|
|
|
|
export function useAttachmentActions() {
|
|
function handleAttachmentPreview(file: Record<string, unknown>) {
|
|
const url = attachmentFullUrl(String(file.fileUrl || ''))
|
|
if (url) window.open(url, '_blank')
|
|
}
|
|
|
|
function handleAttachmentDownload(file: Record<string, unknown>) {
|
|
downloadAttachmentFile(file, {
|
|
fullFileUrl: (u: string) => attachmentFullUrl(u)
|
|
})
|
|
}
|
|
|
|
return {
|
|
handleAttachmentPreview,
|
|
handleAttachmentDownload
|
|
}
|
|
}
|