mirror of
https://github.com/yusufipk/OpenFrame.git
synced 2026-09-11 09:36:08 +00:00
feat: name video downloads by title + version
Downloads now save as "<video title> <version label>" (or "<title> vN" when no label), with the real extension derived from the file's content type, instead of the CDN's generic "original" name. - Bunny (cross-origin CDN redirect) files are fetched and saved as a named blob, but only up to 10 GB; larger files fall back to a plain navigation so the browser streams to disk without buffering in memory. - R2 / S3 / MinIO uploads are same-origin (/api/upload/video/...), so the download attribute names them correctly at any size, no buffering. - Applies to both single-video and bulk/project downloads; bulk downloads run sequentially so at most one file is buffered at a time. - Shared helper in lib/client/download-file.ts.
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
'use client';
|
||||
|
||||
import { downloadNamedFile, navigateDownload } from '@/lib/client/download-file';
|
||||
|
||||
const DOWNLOAD_STAGGER_MS = 500;
|
||||
|
||||
export type ProjectDownloadManifestFile = {
|
||||
@@ -19,21 +21,28 @@ function sleep(ms: number): Promise<void> {
|
||||
return new Promise((resolve) => window.setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
function triggerBrowserDownload(file: ProjectDownloadManifestFile): void {
|
||||
const anchor = document.createElement('a');
|
||||
anchor.href = file.url;
|
||||
anchor.rel = 'noopener';
|
||||
if (file.url.startsWith('/')) {
|
||||
anchor.download = file.fileName;
|
||||
async function triggerBrowserDownload(file: ProjectDownloadManifestFile): Promise<void> {
|
||||
// Same-origin proxy files (R2 / S3 / MinIO via /api/upload/video/...): the
|
||||
// download attribute applies and the browser streams straight to disk, so the
|
||||
// name is correct at any size with no memory cost.
|
||||
if (file.url.startsWith('/api/upload/video/')) {
|
||||
navigateDownload(file.url, file.fileName);
|
||||
return;
|
||||
}
|
||||
|
||||
// Bunny (CDN redirect) and external direct hosts are cross-origin, so the name
|
||||
// only applies if we fetch the bytes. downloadNamedFile does that for files up
|
||||
// to 10 GB; larger ones fall back to a plain navigation (CDN filename).
|
||||
const saved = await downloadNamedFile(file.url, file.fileName);
|
||||
if (!saved) {
|
||||
navigateDownload(file.url, file.fileName);
|
||||
}
|
||||
document.body.appendChild(anchor);
|
||||
anchor.click();
|
||||
anchor.remove();
|
||||
}
|
||||
|
||||
export async function runProjectDownloadManifest(manifest: ProjectDownloadManifest): Promise<void> {
|
||||
for (let index = 0; index < manifest.files.length; index += 1) {
|
||||
triggerBrowserDownload(manifest.files[index]!);
|
||||
// Sequential so at most one file is buffered in memory at a time.
|
||||
await triggerBrowserDownload(manifest.files[index]!);
|
||||
if (index < manifest.files.length - 1) {
|
||||
await sleep(DOWNLOAD_STAGGER_MS);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user