Skip to content

Commit

Permalink
Fix: Prevent setting migrations failing (#928)
Browse files Browse the repository at this point in the history
* Fix: Prevent setting migrations failing

* Fix: Add proper error handling for settings migrations
  • Loading branch information
fearnlj01 authored Jun 3, 2024
1 parent cf384cf commit f523fa5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/core/patches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const webuiSettingsPatches = {
delete webuiSettings.collection.poster.showRandomPoster;
webuiSettings.collection.image = {
showRandomPoster:
(oldWebuiSettings?.collection?.list?.showRandomPoster || oldWebuiSettings?.collection?.poster?.showRandomPoster)
(oldWebuiSettings.collection.list.showRandomPoster || oldWebuiSettings.collection.poster.showRandomPoster)
?? false,
showRandomFanart: false,
};
Expand Down
34 changes: 20 additions & 14 deletions src/core/react-query/settings/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,21 +400,27 @@ export const transformSettings = (response: SettingsServerType) => {
let webuiSettings = JSON.parse(
response.WebUI_Settings === '' ? '{}' : response.WebUI_Settings,
) as WebUISettingsType;
const settingsRevision = webuiSettings.settingsRevision ?? 0;
if (settingsRevision < 4) {
webuiSettings = {
...initialSettings.WebUI_Settings,
settingsRevision: Number(Object.keys(webuiSettingsPatches).pop()),
};
const currentSettingsRevision = webuiSettings.settingsRevision ?? 0;
const versionedInitialSettings: WebUISettingsType = {
...initialSettings.WebUI_Settings,
settingsRevision: Number(Object.keys(webuiSettingsPatches).pop()),
};

if (currentSettingsRevision < 4) {
webuiSettings = versionedInitialSettings;
} else {
Object
.keys(webuiSettingsPatches)
.map(Number)
.filter(key => key > settingsRevision)
.forEach((key) => {
webuiSettings = webuiSettingsPatches[key](webuiSettings);
});
webuiSettings = Object.assign({}, initialSettings.WebUI_Settings, webuiSettings);
try {
Object
.keys(webuiSettingsPatches)
.map(Number)
.filter(key => key > currentSettingsRevision)
.forEach((key) => {
webuiSettings = webuiSettingsPatches[key](webuiSettings);
});
webuiSettings = Object.assign({}, initialSettings.WebUI_Settings, webuiSettings);
} catch {
webuiSettings = versionedInitialSettings;
}
}
return { ...response, WebUI_Settings: webuiSettings } as SettingsType;
// For Dev Only
Expand Down

0 comments on commit f523fa5

Please sign in to comment.