From 6c0354b294557281b5fd094c9dc42f1a77c6a208 Mon Sep 17 00:00:00 2001 From: Maximilien Carbonne Date: Sat, 9 Nov 2024 17:22:45 +0100 Subject: [PATCH 1/2] recursively sort json output (settings) --- web/src/routes/admin/system-settings/+page.svelte | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/web/src/routes/admin/system-settings/+page.svelte b/web/src/routes/admin/system-settings/+page.svelte index f724e2d145951..5b55f388e8c76 100644 --- a/web/src/routes/admin/system-settings/+page.svelte +++ b/web/src/routes/admin/system-settings/+page.svelte @@ -64,8 +64,19 @@ type SettingsComponent = ComponentType>; + // https://stackoverflow.com/questions/16167581/sort-object-properties-and-json-stringify/43636793#43636793 + const jsonReplacer = (key, value) => + value instanceof Object && !(value instanceof Array) ? + Object.keys(value) + .sort() + .reduce((sorted, key) => { + sorted[key] = value[key]; + return sorted + }, {}) : + value; + const downloadConfig = () => { - const blob = new Blob([JSON.stringify(config, null, 2)], { type: 'application/json' }); + const blob = new Blob([JSON.stringify(config, jsonReplacer, 2)], { type: 'application/json' }); const downloadKey = 'immich-config.json'; downloadManager.add(downloadKey, blob.size); downloadManager.update(downloadKey, blob.size); @@ -240,7 +251,7 @@ - copyToClipboard(JSON.stringify(config, null, 2))}> + copyToClipboard(JSON.stringify(config, jsonReplacer, 2))}>
{$t('copy_to_clipboard')} From e8fb58fc586c3886745a59fe6d8cfe706fa303a3 Mon Sep 17 00:00:00 2001 From: Maximilien Carbonne Date: Sat, 9 Nov 2024 18:52:05 +0100 Subject: [PATCH 2/2] fix format/lint/...g --- .../routes/admin/system-settings/+page.svelte | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/web/src/routes/admin/system-settings/+page.svelte b/web/src/routes/admin/system-settings/+page.svelte index 5b55f388e8c76..9eb7351060048 100644 --- a/web/src/routes/admin/system-settings/+page.svelte +++ b/web/src/routes/admin/system-settings/+page.svelte @@ -65,15 +65,16 @@ type SettingsComponent = ComponentType>; // https://stackoverflow.com/questions/16167581/sort-object-properties-and-json-stringify/43636793#43636793 - const jsonReplacer = (key, value) => - value instanceof Object && !(value instanceof Array) ? - Object.keys(value) - .sort() - .reduce((sorted, key) => { - sorted[key] = value[key]; - return sorted - }, {}) : - value; + const jsonReplacer = (key: string, value: unknown) => + value instanceof Object && !Array.isArray(value) + ? Object.keys(value) + .sort() + // eslint-disable-next-line unicorn/no-array-reduce + .reduce((sorted: { [key: string]: unknown }, key) => { + sorted[key] = (value as { [key: string]: unknown })[key]; + return sorted; + }, {}) + : value; const downloadConfig = () => { const blob = new Blob([JSON.stringify(config, jsonReplacer, 2)], { type: 'application/json' });