mirror of
https://github.com/nimbold/Firelink.git
synced 2026-08-10 19:47:42 +00:00
fix(core): harden download lifecycle and scheduling
This commit is contained in:
@@ -2,6 +2,7 @@ import type { DownloadStatus } from '../bindings/DownloadStatus';
|
||||
|
||||
const STARTABLE_STATUSES: ReadonlySet<DownloadStatus> = new Set([
|
||||
'ready',
|
||||
'staged',
|
||||
'paused',
|
||||
'failed',
|
||||
]);
|
||||
@@ -29,7 +30,7 @@ export const canRedownload = (status: DownloadStatus): boolean =>
|
||||
REDOWNLOADABLE_STATUSES.has(status);
|
||||
|
||||
export const startActionLabel = (status: DownloadStatus): 'Start' | 'Resume' =>
|
||||
status === 'ready' || status === 'failed' ? 'Start' : 'Resume';
|
||||
status === 'ready' || status === 'staged' || status === 'failed' ? 'Start' : 'Resume';
|
||||
|
||||
export const isTransferLocked = (status: DownloadStatus): boolean =>
|
||||
status === 'downloading' || status === 'processing' || status === 'retrying';
|
||||
|
||||
@@ -83,6 +83,15 @@ export const fileNameFromUrl = (rawUrl: string): string => {
|
||||
return 'download';
|
||||
};
|
||||
|
||||
export const canonicalizeDownloadFileName = (fileName: string): string => {
|
||||
const leaf = fileName.replace(/\\/g, '/').split('/').pop() || 'download';
|
||||
const sanitized = leaf
|
||||
.replace(/[\u0000-\u001f<>:"/\\|?*]/g, '-')
|
||||
.trim()
|
||||
.replace(/[. ]+$/g, '');
|
||||
return sanitized && sanitized !== '.' && sanitized !== '..' ? sanitized : 'download';
|
||||
};
|
||||
|
||||
export const isMediaUrl = (rawUrl: string): boolean => {
|
||||
try {
|
||||
const url = new URL(rawUrl);
|
||||
|
||||
Reference in New Issue
Block a user