mirror of
https://github.com/yusufipk/OpenFrame.git
synced 2026-09-11 09:36:08 +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:
@@ -19,6 +19,7 @@ import {
|
||||
extractVideoKeyFromProxyUrl,
|
||||
getVideoAssetAccessContext,
|
||||
sanitizeAssetDisplayName,
|
||||
withFileExtension,
|
||||
SAFE_BUNNY_VIDEO_ID,
|
||||
} from '@/lib/video-assets';
|
||||
import { apiRequest } from '../helpers/request';
|
||||
@@ -83,6 +84,28 @@ describe('sanitizeAssetDisplayName', () => {
|
||||
});
|
||||
});
|
||||
|
||||
// A voice comment is stored under its generated file name, so its display name
|
||||
// already ends in .webm and every download was named `<uuid>.webm.webm`.
|
||||
describe('withFileExtension', () => {
|
||||
it('leaves a name that already ends in the extension alone', () => {
|
||||
expect(withFileExtension('33661b60-b658-47f9-bd40-71c32a0a2fdb.webm', '.webm')).toBe(
|
||||
'33661b60-b658-47f9-bd40-71c32a0a2fdb.webm'
|
||||
);
|
||||
});
|
||||
|
||||
it('ignores the case the extension was written in', () => {
|
||||
expect(withFileExtension('Take 2.WEBM', '.webm')).toBe('Take 2.WEBM');
|
||||
});
|
||||
|
||||
it('appends when the name carries no extension', () => {
|
||||
expect(withFileExtension('Voice Comment', '.webm')).toBe('Voice Comment.webm');
|
||||
});
|
||||
|
||||
it('appends when the name ends in a different extension', () => {
|
||||
expect(withFileExtension('clip.mp4', '.webm')).toBe('clip.mp4.webm');
|
||||
});
|
||||
});
|
||||
|
||||
describe('proxy URL extraction', () => {
|
||||
it('derives the image key and file name from a canonical image URL', () => {
|
||||
expect(extractImageKeyFromProxyUrl(IMAGE_URL)).toBe(
|
||||
|
||||
@@ -1221,6 +1221,30 @@ describe('buildProjectDownloadManifest assets', () => {
|
||||
expect(manifest.files[0]?.fileName).toBe('01-Intro-asset-B roll.png');
|
||||
});
|
||||
|
||||
// A voice comment's display name is the stored file name, extension included.
|
||||
it('does not repeat an extension the display name already carries', () => {
|
||||
const manifest = buildProjectDownloadManifest(
|
||||
'Project',
|
||||
[
|
||||
video({
|
||||
versions: [],
|
||||
assets: [
|
||||
asset({
|
||||
provider: VideoAssetProvider.R2_AUDIO,
|
||||
displayName: '33661b60-b658-47f9-bd40-71c32a0a2fdb.webm',
|
||||
sourceUrl: '/api/upload/audio/33661b60-b658-47f9-bd40-71c32a0a2fdb.webm',
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
{ includeAssets: true }
|
||||
);
|
||||
|
||||
expect(manifest.files[0]?.fileName).toBe(
|
||||
'01-Intro-asset-33661b60-b658-47f9-bd40-71c32a0a2fdb.webm'
|
||||
);
|
||||
});
|
||||
|
||||
it('always names a bunny asset .mp4 regardless of the source url', () => {
|
||||
const manifest = buildProjectDownloadManifest(
|
||||
'Project',
|
||||
|
||||
Reference in New Issue
Block a user