mirror of
https://github.com/nimbold/Firelink.git
synced 2026-08-08 02:13:24 +00:00
fix(downloads): harden filenames and localized surfaces
Bound generated filenames to cross-platform component limits, preserve extensions, and keep duplicate renames unique. Correct light-theme compositing tokens and enforce Persian date formatting while preserving Hebrew locale formatting. Fixes #29 Refs #31
This commit is contained in:
@@ -3,6 +3,7 @@ import { dispatchItem, getProxyArgs, getSiteLogin, hasStaleTemporaryMediaEstimat
|
||||
import { useDownloadProgressStore } from './downloadProgressStore';
|
||||
import { useSettingsStore } from './useSettingsStore';
|
||||
import * as ipc from '../ipc';
|
||||
import { MAX_DOWNLOAD_FILENAME_BYTES } from '../utils/downloads';
|
||||
|
||||
vi.mock('../ipc', () => ({
|
||||
invokeCommand: vi.fn(),
|
||||
@@ -113,6 +114,27 @@ describe('useDownloadStore', () => {
|
||||
expect(useDownloadStore.getState().pendingAddRequestVersion).toBe(initialVersion + 2);
|
||||
});
|
||||
|
||||
it('normalizes an overlong filename edited in Properties before persisting it', async () => {
|
||||
useDownloadStore.setState({
|
||||
downloads: [{
|
||||
id: 'properties-long-name',
|
||||
url: 'https://example.com/video',
|
||||
fileName: 'video.mp4',
|
||||
status: 'ready',
|
||||
category: 'Movies',
|
||||
dateAdded: ''
|
||||
}] as any[]
|
||||
});
|
||||
|
||||
await useDownloadStore.getState().applyProperties('properties-long-name', {
|
||||
fileName: `${'title '.repeat(100)}.mp4`
|
||||
});
|
||||
|
||||
const fileName = useDownloadStore.getState().downloads[0].fileName;
|
||||
expect(new TextEncoder().encode(fileName).length).toBeLessThanOrEqual(MAX_DOWNLOAD_FILENAME_BYTES);
|
||||
expect(fileName.endsWith('.mp4')).toBe(true);
|
||||
});
|
||||
|
||||
it('replaces stale media intent when an appended handoff reuses a URL', () => {
|
||||
useDownloadStore.getState().openAddModalWithUrls(
|
||||
'https://example.com/file.bin', '', '', '', '', true
|
||||
@@ -1563,7 +1585,7 @@ describe('useDownloadStore', () => {
|
||||
})];
|
||||
}
|
||||
if (cmd === 'enqueue_many') {
|
||||
return [{ id: 'startup-accepted', success: true, filename: 'file.bin' }];
|
||||
return [{ id: 'startup-accepted', success: true, filename: 'normalized.bin' }];
|
||||
}
|
||||
if (cmd === 'get_pending_order') throw new Error('queue state unavailable');
|
||||
if (cmd === 'resume_download') return true;
|
||||
@@ -1575,6 +1597,7 @@ describe('useDownloadStore', () => {
|
||||
|
||||
expect(useDownloadStore.getState().backendRegisteredIds.has('startup-accepted')).toBe(true);
|
||||
expect(useDownloadStore.getState().downloads[0]).toMatchObject({
|
||||
fileName: 'normalized.bin',
|
||||
status: 'queued',
|
||||
hasBeenDispatched: true
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user