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:
yusufipk
2026-07-30 23:13:04 +07:00
parent e7008c571a
commit 93e85683e9
5 changed files with 69 additions and 8 deletions
+23
View File
@@ -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(
+24
View File
@@ -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',