feat(downloads): add dedicated Torrent category

This commit is contained in:
NimBold
2026-08-10 14:20:50 +03:30
parent 23991c3dea
commit 472da5a681
22 changed files with 150 additions and 25 deletions
+14 -1
View File
@@ -417,7 +417,11 @@ export const initMediaDomains = async () => {
}
};
export const categoryForFileName = (fileName: string): DownloadCategory => {
export const categoryForFileName = (
fileName: string,
isTorrent = false
): DownloadCategory => {
if (isTorrent || fileName.trim().toLowerCase().endsWith('.torrent')) return 'Torrents';
const ext = fileName.split('.').pop()?.toLowerCase() || '';
if (['mp4', 'mkv', 'avi', 'mov', 'wmv', 'flv', 'webm', 'm4v', 'mpeg', 'mpg', '3gp', 'ts', 'vob'].includes(ext)) return 'Movies';
if (['mp3', 'wav', 'aac', 'flac', 'ogg', 'm4a', 'wma', 'alac', 'ape', 'mid', 'midi'].includes(ext)) return 'Musics';
@@ -428,6 +432,15 @@ export const categoryForFileName = (fileName: string): DownloadCategory => {
return 'Other';
};
export const categoryForDownload = (
fileName: string,
isTorrent: boolean,
existingCategory?: DownloadCategory
): DownloadCategory => {
if (isTorrent && existingCategory === 'Other') return existingCategory;
return categoryForFileName(fileName, isTorrent);
};
export const fileNameFromUrl = (rawUrl: string): string => {
try {
const url = new URL(rawUrl);