mirror of
https://github.com/imputnet/cobalt.git
synced 2024-12-28 18:46:09 +00:00
web/settings/migrate: refactor, migrate to v4 schema
why the fuck was tab 2 spaces here
This commit is contained in:
parent
0b6270e745
commit
57734822ea
|
@ -2,13 +2,13 @@ import type { RecursivePartial } from "$lib/types/generic";
|
||||||
import type {
|
import type {
|
||||||
AllPartialSettingsWithSchema,
|
AllPartialSettingsWithSchema,
|
||||||
CobaltSettingsV3,
|
CobaltSettingsV3,
|
||||||
|
CobaltSettingsV4,
|
||||||
PartialSettings,
|
PartialSettings,
|
||||||
} from "$lib/types/settings";
|
} from "$lib/types/settings";
|
||||||
import { getBrowserLanguage } from "$lib/settings/youtube-lang";
|
import { getBrowserLanguage } from "$lib/settings/youtube-lang";
|
||||||
|
|
||||||
type Migrator = (
|
type Migrator = (s: AllPartialSettingsWithSchema) => AllPartialSettingsWithSchema;
|
||||||
s: AllPartialSettingsWithSchema
|
|
||||||
) => AllPartialSettingsWithSchema;
|
|
||||||
const migrations: Record<number, Migrator> = {
|
const migrations: Record<number, Migrator> = {
|
||||||
[3]: (settings: AllPartialSettingsWithSchema) => {
|
[3]: (settings: AllPartialSettingsWithSchema) => {
|
||||||
const out = settings as RecursivePartial<CobaltSettingsV3>;
|
const out = settings as RecursivePartial<CobaltSettingsV3>;
|
||||||
|
@ -24,11 +24,25 @@ const migrations: Record<number, Migrator> = {
|
||||||
|
|
||||||
return out as AllPartialSettingsWithSchema;
|
return out as AllPartialSettingsWithSchema;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
[4]: (settings: AllPartialSettingsWithSchema) => {
|
||||||
|
const out = settings as RecursivePartial<CobaltSettingsV4>;
|
||||||
|
out.schemaVersion = 4;
|
||||||
|
|
||||||
|
if (settings?.processing) {
|
||||||
|
if ("allowDefaultOverride" in settings.processing) {
|
||||||
|
delete settings.processing.allowDefaultOverride;
|
||||||
|
}
|
||||||
|
if ("seenOverrideWarning" in settings.processing) {
|
||||||
|
delete settings.processing.seenOverrideWarning;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return out as AllPartialSettingsWithSchema;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const migrate = (
|
export const migrate = (settings: AllPartialSettingsWithSchema): PartialSettings => {
|
||||||
settings: AllPartialSettingsWithSchema
|
|
||||||
): PartialSettings => {
|
|
||||||
return Object.keys(migrations)
|
return Object.keys(migrations)
|
||||||
.map(Number)
|
.map(Number)
|
||||||
.filter((version) => version > settings.schemaVersion)
|
.filter((version) => version > settings.schemaVersion)
|
||||||
|
|
Loading…
Reference in a new issue