mirror of
https://github.com/nimbold/Firelink.git
synced 2026-08-10 11:37:21 +00:00
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:
@@ -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',
|
||||
|
||||
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user