mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
add: more commits
Signed-off-by: Kenneth Obsequio <k80308392@gmail.com>
This commit is contained in:
@@ -36,6 +36,7 @@ import {
|
||||
import { formatDate } from '@/utils/table.util';
|
||||
import { formatBytes } from './blocks/FileUpload';
|
||||
import api from '@/utils/api.util';
|
||||
import { saveBlob } from '@/utils/media.util';
|
||||
import FileZoomViewer from './FileZoomViewer';
|
||||
|
||||
// ─── Resolve preview kind from mime type ──────────────────────────────────────
|
||||
@@ -190,18 +191,6 @@ const PreviewBody = ({ file, kind, blobUrl, loading, error, downloadUrl, onDownl
|
||||
}
|
||||
};
|
||||
|
||||
// ─── Trigger a browser download from a blob ────────────────────────────────────
|
||||
const downloadBlob = (blob, fileName) => {
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = fileName;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
URL.revokeObjectURL(url);
|
||||
};
|
||||
|
||||
// ─── Main dialog ────────────────────────────────────────────────────────────────
|
||||
const FilePreview = ({ file, open, onOpenChange, streamUrl, downloadUrl }) => {
|
||||
const kind = file ? resolveKind(file.mime_type, file.file_name) : 'other';
|
||||
@@ -223,7 +212,7 @@ const FilePreview = ({ file, open, onOpenChange, streamUrl, downloadUrl }) => {
|
||||
setDownloading(true);
|
||||
try {
|
||||
const res = await api.get(url, { responseType: 'blob' });
|
||||
downloadBlob(res.data, file.file_name);
|
||||
saveBlob(res.data, file.file_name);
|
||||
} catch {
|
||||
// fall back to direct link if proxy fails (e.g. public file_url)
|
||||
if (file.file_url) window.open(file.file_url, '_blank');
|
||||
|
||||
Reference in New Issue
Block a user