mirror of
https://github.com/immich-app/immich.git
synced 2024-12-29 15:11:58 +00:00
feat(web): stable json settings export (#14036)
* recursively sort json output (settings) * fix format/lint/...g
This commit is contained in:
parent
6b49104d59
commit
5c31acbcf0
1 changed files with 14 additions and 2 deletions
|
@ -64,8 +64,20 @@
|
||||||
|
|
||||||
type SettingsComponent = ComponentType<SvelteComponent<SettingsComponentProps>>;
|
type SettingsComponent = ComponentType<SvelteComponent<SettingsComponentProps>>;
|
||||||
|
|
||||||
|
// https://stackoverflow.com/questions/16167581/sort-object-properties-and-json-stringify/43636793#43636793
|
||||||
|
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 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';
|
const downloadKey = 'immich-config.json';
|
||||||
downloadManager.add(downloadKey, blob.size);
|
downloadManager.add(downloadKey, blob.size);
|
||||||
downloadManager.update(downloadKey, blob.size);
|
downloadManager.update(downloadKey, blob.size);
|
||||||
|
@ -240,7 +252,7 @@
|
||||||
<div class="hidden lg:block">
|
<div class="hidden lg:block">
|
||||||
<SearchBar placeholder={$t('search_settings')} bind:name={searchQuery} showLoadingSpinner={false} />
|
<SearchBar placeholder={$t('search_settings')} bind:name={searchQuery} showLoadingSpinner={false} />
|
||||||
</div>
|
</div>
|
||||||
<LinkButton on:click={() => copyToClipboard(JSON.stringify(config, null, 2))}>
|
<LinkButton on:click={() => copyToClipboard(JSON.stringify(config, jsonReplacer, 2))}>
|
||||||
<div class="flex place-items-center gap-2 text-sm">
|
<div class="flex place-items-center gap-2 text-sm">
|
||||||
<Icon path={mdiContentCopy} size="18" />
|
<Icon path={mdiContentCopy} size="18" />
|
||||||
{$t('copy_to_clipboard')}
|
{$t('copy_to_clipboard')}
|
||||||
|
|
Loading…
Reference in a new issue