mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-12 08:25:47 +01:00
Add config migration process
This commit is contained in:
@@ -1,9 +1,18 @@
|
||||
import { BackendConfigType, ConfigType } from '../../types/config';
|
||||
import { BackendConfigType } from '../../types/config';
|
||||
import { configExists } from './configExists';
|
||||
import { getFallbackConfig } from './getFallbackConfig';
|
||||
import { migrateConfig } from './migrateConfig';
|
||||
import { readConfig } from './readConfig';
|
||||
|
||||
export const getConfig = (name: string): BackendConfigType => {
|
||||
if (!configExists(name)) return getFallbackConfig();
|
||||
return readConfig(name);
|
||||
// Else if config exists but contains no "schema_version" property
|
||||
// then it is an old config file and we should try to migrate it
|
||||
// to the new format.
|
||||
let config = readConfig(name);
|
||||
if (!config.schemaVersion) {
|
||||
// TODO: Migrate config to new format
|
||||
config = migrateConfig(config);
|
||||
}
|
||||
return config;
|
||||
};
|
||||
|
||||
81
src/tools/config/migrateConfig.ts
Normal file
81
src/tools/config/migrateConfig.ts
Normal file
@@ -0,0 +1,81 @@
|
||||
import { ConfigType } from '../../types/config';
|
||||
import { Config } from '../types';
|
||||
|
||||
export function migrateConfig(config: Config): ConfigType {
|
||||
const newConfig: ConfigType = {
|
||||
schemaVersion: '1.0.0',
|
||||
configProperties: {
|
||||
name: config.name ?? 'default',
|
||||
},
|
||||
categories: [],
|
||||
widgets: [],
|
||||
apps: [],
|
||||
settings: {
|
||||
common: {
|
||||
searchEngine: {
|
||||
type: 'google',
|
||||
properties: {
|
||||
enabled: true,
|
||||
openInNewTab: true,
|
||||
},
|
||||
},
|
||||
defaultConfig: 'default',
|
||||
},
|
||||
customization: {
|
||||
colors: {},
|
||||
layout: {
|
||||
enabledDocker: false,
|
||||
enabledLeftSidebar: false,
|
||||
enabledPing: false,
|
||||
enabledRightSidebar: false,
|
||||
enabledSearchbar: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
wrappers: [
|
||||
{
|
||||
id: 'default',
|
||||
position: 1,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
newConfig.apps = config.services.map((s, idx) => ({
|
||||
name: s.name,
|
||||
id: s.id,
|
||||
url: s.url,
|
||||
behaviour: {
|
||||
isOpeningNewTab: s.newTab ?? true,
|
||||
externalUrl: s.openedUrl ?? '',
|
||||
},
|
||||
network: {
|
||||
enabledStatusChecker: s.ping ?? true,
|
||||
okStatus: s.status?.map((str) => parseInt(str, 10)) ?? [200],
|
||||
},
|
||||
appearance: {
|
||||
iconUrl: s.icon,
|
||||
},
|
||||
integration: {
|
||||
type: null,
|
||||
properties: [],
|
||||
},
|
||||
area: {
|
||||
type: 'wrapper',
|
||||
properties: {
|
||||
id: 'default',
|
||||
},
|
||||
},
|
||||
shape: {
|
||||
location: {
|
||||
x: (idx * 3) % 18,
|
||||
y: Math.floor((idx / 6)) * 3,
|
||||
},
|
||||
size: {
|
||||
width: 3,
|
||||
height: 3,
|
||||
},
|
||||
},
|
||||
}));
|
||||
|
||||
return newConfig;
|
||||
}
|
||||
@@ -20,7 +20,7 @@ export interface Settings {
|
||||
|
||||
export interface Config {
|
||||
name: string;
|
||||
apps: serviceItem[];
|
||||
services: serviceItem[];
|
||||
settings: Settings;
|
||||
modules: {
|
||||
[key: string]: ConfigModule;
|
||||
|
||||
Reference in New Issue
Block a user