mirror of
https://github.com/yusufipk/OpenFrame.git
synced 2026-09-11 17:46:06 +00:00
fix(downloads): stop repeating an extension the name already carries
A voice comment's display name is the generated file name, extension included, so appending the extension again downloaded it as <uuid>.webm.webm. Both download paths, the single asset route and the project zip, now append only when the name does not already end in it.
This commit is contained in:
@@ -4,6 +4,7 @@ import {
|
||||
extractImageFileNameFromProxyUrl,
|
||||
extractVideoFileNameFromProxyUrl,
|
||||
sanitizeAssetDisplayName,
|
||||
withFileExtension,
|
||||
} from '@/lib/video-assets';
|
||||
|
||||
const DEFAULT_MAX_FILES = 250;
|
||||
@@ -171,21 +172,21 @@ function buildAssetFileName(videoIndex: number, videoTitle: string, asset: Asset
|
||||
|
||||
if (asset.provider === VideoAssetProvider.R2_IMAGE) {
|
||||
const fileName = extractImageFileNameFromProxyUrl(asset.sourceUrl);
|
||||
return `${stem}${extensionFromUrl(fileName ?? '', '.png')}`;
|
||||
return withFileExtension(stem, extensionFromUrl(fileName ?? '', '.png'));
|
||||
}
|
||||
if (asset.provider === VideoAssetProvider.R2_AUDIO) {
|
||||
const fileName = extractAudioFileNameFromProxyUrl(asset.sourceUrl);
|
||||
return `${stem}${extensionFromUrl(fileName ?? '', '.webm')}`;
|
||||
return withFileExtension(stem, extensionFromUrl(fileName ?? '', '.webm'));
|
||||
}
|
||||
if (asset.provider === VideoAssetProvider.R2_VIDEO) {
|
||||
const fileName = extractVideoFileNameFromProxyUrl(asset.sourceUrl);
|
||||
return `${stem}${extensionFromUrl(fileName ?? '', '.mp4')}`;
|
||||
return withFileExtension(stem, extensionFromUrl(fileName ?? '', '.mp4'));
|
||||
}
|
||||
if (asset.provider === VideoAssetProvider.BUNNY) {
|
||||
return `${stem}.mp4`;
|
||||
return withFileExtension(stem, '.mp4');
|
||||
}
|
||||
|
||||
return `${stem}.bin`;
|
||||
return withFileExtension(stem, '.bin');
|
||||
}
|
||||
|
||||
function versionDownloadUrl(version: VersionRow): string | null {
|
||||
|
||||
@@ -66,6 +66,14 @@ export function sanitizeAssetDisplayName(
|
||||
return normalized.slice(0, 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* A voice comment's display name is the generated file name, extension and all,
|
||||
* so blindly appending the extension named the download `<uuid>.webm.webm`.
|
||||
*/
|
||||
export function withFileExtension(name: string, extension: string): string {
|
||||
return name.toLowerCase().endsWith(extension.toLowerCase()) ? name : `${name}${extension}`;
|
||||
}
|
||||
|
||||
export function extractImageKeyFromProxyUrl(url: string): string | null {
|
||||
if (!SAFE_IMAGE_PROXY_PATH.test(url)) return null;
|
||||
const filename = url.slice(IMAGE_PROXY_PREFIX.length);
|
||||
|
||||
Reference in New Issue
Block a user