fix(settings): add category subfolders toggle

Add a Settings > Locations toggle that disables automatic category subfolders while keeping the selected base download folder as the automatic destination.

Persist the setting across frontend and backend startup paths and disable the category subfolder controls when the feature is off.

Fixes #6
This commit is contained in:
NimBold
2026-07-06 23:37:03 +03:30
parent 036ff02dac
commit 85ad9d18e8
9 changed files with 123 additions and 25 deletions
+20
View File
@@ -65,6 +65,26 @@ describe('download locations', () => {
expect(await resolveCategoryDestination(automatic, 'Movies')).toBe('/Volumes/Media');
});
it('defaults category subfolders on and sends every category to the base folder when disabled', async () => {
const automatic = normalizeDownloadLocationSettings({
baseDownloadFolder: '/Users/test/Downloads'
});
expect(automatic.categorySubfoldersEnabled).toBe(true);
const disabled = normalizeDownloadLocationSettings({
baseDownloadFolder: '/Users/test/Downloads',
categorySubfoldersEnabled: false,
categorySubfolders: { Movies: 'Video Files' },
categoryDirectoryOverrides: { Movies: '/Volumes/Media' }
});
expect(disabled.categorySubfoldersEnabled).toBe(false);
expect(await resolveCategoryDestination(disabled, 'Movies'))
.toBe('/Users/test/Downloads');
expect(await resolveCategoryDestination(disabled, 'Documents'))
.toBe('/Users/test/Downloads');
});
it('keeps an explicit empty category subfolder as the base folder', async () => {
const settings = normalizeDownloadLocationSettings({
baseDownloadFolder: '/Users/test/Downloads',
+8 -2
View File
@@ -34,12 +34,14 @@ export const DEFAULT_CATEGORY_SUBFOLDERS: Record<DownloadCategory, string> = {
export interface DownloadLocationSettings {
baseDownloadFolder: string;
categorySubfoldersEnabled: boolean;
categorySubfolders: Record<string, string>;
categoryDirectoryOverrides: Record<string, string>;
}
interface LegacyDownloadLocationSettings {
baseDownloadFolder?: unknown;
categorySubfoldersEnabled?: unknown;
categorySubfolders?: unknown;
categoryDirectoryOverrides?: unknown;
defaultDownloadPath?: unknown;
@@ -114,6 +116,7 @@ export const normalizeDownloadLocationSettings = (
(typeof value.baseDownloadFolder === 'string' && value.baseDownloadFolder.trim()) ||
(typeof value.defaultDownloadPath === 'string' && value.defaultDownloadPath.trim()) ||
'~/Downloads';
const categorySubfoldersEnabled = value.categorySubfoldersEnabled !== false;
const persistedSubfolders = stringRecord(value.categorySubfolders);
const categorySubfolders = Object.fromEntries(
DOWNLOAD_CATEGORIES.map(category => {
@@ -150,6 +153,7 @@ export const normalizeDownloadLocationSettings = (
return {
baseDownloadFolder,
categorySubfoldersEnabled,
categorySubfolders,
categoryDirectoryOverrides
};
@@ -159,11 +163,13 @@ export const resolveCategoryDestination = async (
settings: DownloadLocationSettings,
category: DownloadCategory
): Promise<string> => {
const base = settings.baseDownloadFolder.trim() || '~/Downloads';
const expandedBase = await expandTilde(base);
if (!settings.categorySubfoldersEnabled) return expandedBase;
const override = settings.categoryDirectoryOverrides[category]?.trim();
if (override) return expandTilde(override);
const base = settings.baseDownloadFolder.trim() || '~/Downloads';
const expandedBase = await expandTilde(base);
const persistedValue = hasOwn(settings.categorySubfolders, category)
? settings.categorySubfolders[category]
: DEFAULT_CATEGORY_SUBFOLDERS[category];