2023-01-07 20:18:53 +01:00
|
|
|
import Consola from 'consola';
|
2022-12-31 23:31:41 +01:00
|
|
|
import { v4 as uuidv4 } from 'uuid';
|
2023-01-07 20:18:53 +01:00
|
|
|
import { AppIntegrationType, AppType, IntegrationType } from '../../types/app';
|
2022-12-31 23:31:41 +01:00
|
|
|
import { AreaType } from '../../types/area';
|
|
|
|
|
import { CategoryType } from '../../types/category';
|
2022-12-22 11:29:51 +09:00
|
|
|
import { ConfigType } from '../../types/config';
|
2023-01-07 20:18:53 +01:00
|
|
|
import { IBitTorrent } from '../../widgets/bitTorrent/BitTorrentTile';
|
2023-01-08 13:30:25 +09:00
|
|
|
import { ICalendarWidget } from '../../widgets/calendar/CalendarTile';
|
2023-01-07 20:18:53 +01:00
|
|
|
import { IDashDotTile } from '../../widgets/dashDot/DashDotTile';
|
|
|
|
|
import { IDateWidget } from '../../widgets/date/DateTile';
|
|
|
|
|
import { ITorrentNetworkTraffic } from '../../widgets/torrentNetworkTraffic/TorrentNetworkTrafficTile';
|
2023-01-08 13:30:25 +09:00
|
|
|
import { IUsenetWidget } from '../../widgets/useNet/UseNetTile';
|
2023-01-07 20:18:53 +01:00
|
|
|
import { IWeatherWidget } from '../../widgets/weather/WeatherTile';
|
|
|
|
|
import { IWidget } from '../../widgets/widgets';
|
2022-12-31 23:31:41 +01:00
|
|
|
import { Config, serviceItem } from '../types';
|
2022-12-22 11:29:51 +09:00
|
|
|
|
2022-12-31 23:31:41 +01:00
|
|
|
export function migrateConfig(config: Config): ConfigType {
|
2022-12-22 11:29:51 +09:00
|
|
|
const newConfig: ConfigType = {
|
2022-12-24 17:18:16 +09:00
|
|
|
schemaVersion: 1,
|
2022-12-22 11:29:51 +09:00
|
|
|
configProperties: {
|
|
|
|
|
name: config.name ?? 'default',
|
|
|
|
|
},
|
|
|
|
|
categories: [],
|
2023-01-07 20:18:53 +01:00
|
|
|
widgets: migrateModules(config),
|
2022-12-22 11:29:51 +09:00
|
|
|
apps: [],
|
|
|
|
|
settings: {
|
|
|
|
|
common: {
|
|
|
|
|
searchEngine: {
|
|
|
|
|
type: 'google',
|
|
|
|
|
properties: {
|
|
|
|
|
enabled: true,
|
|
|
|
|
openInNewTab: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
defaultConfig: 'default',
|
|
|
|
|
},
|
|
|
|
|
customization: {
|
2023-01-07 20:18:53 +01:00
|
|
|
colors: {
|
2023-01-07 23:25:13 +01:00
|
|
|
primary: config.settings.primaryColor ?? 'red',
|
|
|
|
|
secondary: config.settings.secondaryColor ?? 'orange',
|
|
|
|
|
shade: config.settings.primaryShade ?? 7,
|
2023-01-07 20:18:53 +01:00
|
|
|
},
|
2022-12-22 11:29:51 +09:00
|
|
|
layout: {
|
2023-01-07 20:18:53 +01:00
|
|
|
enabledDocker: config.modules.docker?.enabled ?? false,
|
2022-12-22 11:29:51 +09:00
|
|
|
enabledLeftSidebar: false,
|
2023-01-07 20:18:53 +01:00
|
|
|
enabledPing: config.modules.ping?.enabled ?? false,
|
2022-12-22 11:29:51 +09:00
|
|
|
enabledRightSidebar: false,
|
2023-01-07 20:18:53 +01:00
|
|
|
enabledSearchbar: config.modules.search?.enabled ?? true,
|
2022-12-22 11:29:51 +09:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
wrappers: [
|
|
|
|
|
{
|
|
|
|
|
id: 'default',
|
|
|
|
|
position: 1,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
};
|
|
|
|
|
|
2023-01-08 01:38:21 +01:00
|
|
|
config.services.forEach((service) => {
|
2022-12-31 23:31:41 +01:00
|
|
|
const { category: categoryName } = service;
|
|
|
|
|
|
|
|
|
|
if (!categoryName) {
|
|
|
|
|
newConfig.apps.push(
|
2023-01-07 23:25:13 +01:00
|
|
|
migrateService(service, {
|
2022-12-31 23:31:41 +01:00
|
|
|
type: 'wrapper',
|
|
|
|
|
properties: {
|
|
|
|
|
id: 'default',
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const category = getConfigAndCreateIfNotExsists(newConfig, categoryName);
|
|
|
|
|
|
|
|
|
|
if (!category) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
newConfig.apps.push(
|
2023-01-07 23:25:13 +01:00
|
|
|
migrateService(service, { type: 'category', properties: { id: category.id } })
|
2022-12-31 23:31:41 +01:00
|
|
|
);
|
|
|
|
|
});
|
2022-12-22 11:29:51 +09:00
|
|
|
|
|
|
|
|
return newConfig;
|
|
|
|
|
}
|
2022-12-31 23:31:41 +01:00
|
|
|
|
|
|
|
|
const getConfigAndCreateIfNotExsists = (
|
|
|
|
|
config: ConfigType,
|
|
|
|
|
categoryName: string
|
|
|
|
|
): CategoryType | null => {
|
|
|
|
|
const foundCategory = config.categories.find((c) => c.name === categoryName);
|
|
|
|
|
if (foundCategory) {
|
|
|
|
|
return foundCategory;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const category: CategoryType = {
|
|
|
|
|
id: uuidv4(),
|
|
|
|
|
name: categoryName,
|
2023-01-08 01:38:21 +01:00
|
|
|
position: config.categories.length,
|
2022-12-31 23:31:41 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
config.categories.push(category);
|
|
|
|
|
return category;
|
|
|
|
|
};
|
|
|
|
|
|
2023-01-07 23:25:13 +01:00
|
|
|
const migrateService = (oldService: serviceItem, areaType: AreaType): AppType => ({
|
2022-12-31 23:31:41 +01:00
|
|
|
id: uuidv4(),
|
|
|
|
|
name: oldService.name,
|
|
|
|
|
url: oldService.url,
|
|
|
|
|
behaviour: {
|
|
|
|
|
isOpeningNewTab: oldService.newTab ?? true,
|
|
|
|
|
externalUrl: oldService.openedUrl ?? '',
|
|
|
|
|
},
|
|
|
|
|
network: {
|
|
|
|
|
enabledStatusChecker: oldService.ping ?? true,
|
|
|
|
|
okStatus: oldService.status?.map((str) => parseInt(str, 10)) ?? [200],
|
|
|
|
|
},
|
|
|
|
|
appearance: {
|
2023-01-07 19:14:40 +01:00
|
|
|
iconUrl: migrateIcon(oldService.icon),
|
2022-12-31 23:31:41 +01:00
|
|
|
},
|
2023-01-07 20:18:53 +01:00
|
|
|
integration: migrateIntegration(oldService),
|
2022-12-31 23:31:41 +01:00
|
|
|
area: areaType,
|
2023-01-07 23:25:13 +01:00
|
|
|
shape: {},
|
2022-12-31 23:31:41 +01:00
|
|
|
});
|
2023-01-07 19:14:40 +01:00
|
|
|
|
2023-01-07 20:18:53 +01:00
|
|
|
const migrateModules = (config: Config): IWidget<string, any>[] => {
|
|
|
|
|
const moduleKeys = Object.keys(config.modules);
|
|
|
|
|
return moduleKeys
|
|
|
|
|
.map((moduleKey): IWidget<string, any> | null => {
|
|
|
|
|
const oldModule = config.modules[moduleKey];
|
|
|
|
|
|
|
|
|
|
if (!oldModule.enabled) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (moduleKey.toLowerCase()) {
|
|
|
|
|
case 'torrent-status':
|
|
|
|
|
case 'Torrent':
|
|
|
|
|
return {
|
2023-01-08 13:30:25 +09:00
|
|
|
id: 'torrents-status',
|
2023-01-07 20:18:53 +01:00
|
|
|
properties: {
|
|
|
|
|
refreshInterval: 10,
|
|
|
|
|
displayCompletedTorrents: oldModule.options?.hideComplete?.value ?? false,
|
|
|
|
|
displayStaleTorrents: true,
|
|
|
|
|
},
|
|
|
|
|
area: {
|
|
|
|
|
type: 'wrapper',
|
|
|
|
|
properties: {
|
|
|
|
|
id: 'default',
|
|
|
|
|
},
|
|
|
|
|
},
|
2023-01-08 01:38:21 +01:00
|
|
|
shape: {},
|
2023-01-07 20:18:53 +01:00
|
|
|
} as IBitTorrent;
|
|
|
|
|
case 'weather':
|
|
|
|
|
return {
|
2023-01-08 13:30:25 +09:00
|
|
|
id: 'weather',
|
2023-01-07 20:18:53 +01:00
|
|
|
properties: {
|
|
|
|
|
displayInFahrenheit: oldModule.options?.freedomunit?.value ?? false,
|
|
|
|
|
location: oldModule.options?.location?.value ?? 'Paris',
|
|
|
|
|
},
|
2023-01-08 01:38:21 +01:00
|
|
|
area: {
|
|
|
|
|
type: 'wrapper',
|
|
|
|
|
properties: {
|
|
|
|
|
id: 'default',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
shape: {},
|
2023-01-07 20:18:53 +01:00
|
|
|
} as IWeatherWidget;
|
|
|
|
|
case 'dashdot':
|
|
|
|
|
case 'Dash.':
|
|
|
|
|
return {
|
2023-01-08 13:30:25 +09:00
|
|
|
id: 'dashdot',
|
2023-01-07 20:18:53 +01:00
|
|
|
properties: {
|
|
|
|
|
url: oldModule.options?.url?.value ?? '',
|
|
|
|
|
cpuMultiView: oldModule.options?.cpuMultiView?.value ?? false,
|
|
|
|
|
storageMultiView: oldModule.options?.storageMultiView?.value ?? false,
|
|
|
|
|
useCompactView: oldModule.options?.useCompactView?.value ?? false,
|
|
|
|
|
graphs: oldModule.options?.graphs?.value ?? ['cpu', 'ram'],
|
|
|
|
|
},
|
2023-01-08 01:38:21 +01:00
|
|
|
area: {
|
|
|
|
|
type: 'wrapper',
|
|
|
|
|
properties: {
|
|
|
|
|
id: 'default',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
shape: {},
|
2023-01-07 20:18:53 +01:00
|
|
|
} as IDashDotTile;
|
|
|
|
|
case 'date':
|
|
|
|
|
return {
|
2023-01-08 13:30:25 +09:00
|
|
|
id: 'date',
|
2023-01-07 20:18:53 +01:00
|
|
|
properties: {
|
|
|
|
|
display24HourFormat: oldModule.options?.full?.value ?? true,
|
|
|
|
|
},
|
2023-01-08 01:38:21 +01:00
|
|
|
area: {
|
|
|
|
|
type: 'wrapper',
|
|
|
|
|
properties: {
|
|
|
|
|
id: 'default',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
shape: {},
|
2023-01-07 20:18:53 +01:00
|
|
|
} as IDateWidget;
|
2023-01-08 13:30:25 +09:00
|
|
|
case 'Download Speed' || 'dlspeed':
|
2023-01-07 20:18:53 +01:00
|
|
|
return {
|
2023-01-08 13:30:25 +09:00
|
|
|
id: 'dlspeed',
|
2023-01-07 20:18:53 +01:00
|
|
|
properties: {},
|
2023-01-08 01:38:21 +01:00
|
|
|
area: {
|
|
|
|
|
type: 'wrapper',
|
|
|
|
|
properties: {
|
|
|
|
|
id: 'default',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
shape: {},
|
2023-01-07 20:18:53 +01:00
|
|
|
} as ITorrentNetworkTraffic;
|
2023-01-08 13:30:25 +09:00
|
|
|
case 'calendar':
|
|
|
|
|
return {
|
|
|
|
|
id: 'calendar',
|
|
|
|
|
properties: {},
|
|
|
|
|
area: {
|
|
|
|
|
type: 'wrapper',
|
|
|
|
|
properties: {
|
|
|
|
|
id: 'default',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
shape: {},
|
|
|
|
|
} as ICalendarWidget;
|
|
|
|
|
case 'usenet':
|
|
|
|
|
return {
|
|
|
|
|
id: 'usenet',
|
|
|
|
|
properties: {},
|
|
|
|
|
area: {
|
|
|
|
|
type: 'wrapper',
|
|
|
|
|
properties: {
|
|
|
|
|
id: 'default',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
shape: {},
|
|
|
|
|
} as IUsenetWidget;
|
2023-01-07 20:18:53 +01:00
|
|
|
default:
|
|
|
|
|
Consola.error(`Failed to map unknown module type ${moduleKey} to new type definitions.`);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.filter((x) => x !== null) as IWidget<string, any>[];
|
|
|
|
|
};
|
|
|
|
|
|
2023-01-07 19:14:40 +01:00
|
|
|
const migrateIcon = (iconUrl: string) => {
|
|
|
|
|
if (iconUrl.startsWith('https://cdn.jsdelivr.net/gh/walkxhub/dashboard-icons/png/')) {
|
|
|
|
|
const icon = iconUrl.split('/').at(-1);
|
2023-01-07 20:18:53 +01:00
|
|
|
Consola.warn(
|
|
|
|
|
`Detected legacy icon repository. Upgrading to replacement repository: ${iconUrl} -> ${icon}`
|
|
|
|
|
);
|
2023-01-07 19:14:40 +01:00
|
|
|
return `https://cdn.jsdelivr.net/gh/walkxcode/dashboard-icons/png/${icon}`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return iconUrl;
|
|
|
|
|
};
|
2023-01-07 20:18:53 +01:00
|
|
|
|
|
|
|
|
const migrateIntegration = (oldService: serviceItem): AppIntegrationType => {
|
|
|
|
|
const logInformation = (newType: IntegrationType) => {
|
|
|
|
|
Consola.info(`Migrated integration ${oldService.type} to the new type ${newType}`);
|
|
|
|
|
};
|
|
|
|
|
switch (oldService.type) {
|
|
|
|
|
case 'Deluge':
|
|
|
|
|
logInformation('deluge');
|
|
|
|
|
return {
|
|
|
|
|
type: 'deluge',
|
|
|
|
|
properties: [
|
|
|
|
|
{
|
|
|
|
|
field: 'password',
|
|
|
|
|
isDefined: oldService.password !== undefined,
|
|
|
|
|
type: 'private',
|
|
|
|
|
value: oldService.password,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
};
|
|
|
|
|
case 'Jellyseerr':
|
|
|
|
|
logInformation('jellyseerr');
|
|
|
|
|
return {
|
|
|
|
|
type: 'jellyseerr',
|
|
|
|
|
properties: [
|
|
|
|
|
{
|
|
|
|
|
field: 'apiKey',
|
|
|
|
|
isDefined: oldService.apiKey !== undefined,
|
|
|
|
|
type: 'private',
|
|
|
|
|
value: oldService.apiKey,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
};
|
|
|
|
|
case 'Overseerr':
|
|
|
|
|
logInformation('overseerr');
|
|
|
|
|
return {
|
|
|
|
|
type: 'overseerr',
|
|
|
|
|
properties: [
|
|
|
|
|
{
|
|
|
|
|
field: 'apiKey',
|
|
|
|
|
isDefined: oldService.apiKey !== undefined,
|
|
|
|
|
type: 'private',
|
|
|
|
|
value: oldService.apiKey,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
};
|
|
|
|
|
case 'Lidarr':
|
|
|
|
|
logInformation('lidarr');
|
|
|
|
|
return {
|
|
|
|
|
type: 'lidarr',
|
|
|
|
|
properties: [
|
|
|
|
|
{
|
|
|
|
|
field: 'apiKey',
|
|
|
|
|
isDefined: oldService.apiKey !== undefined,
|
|
|
|
|
type: 'private',
|
|
|
|
|
value: oldService.apiKey,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
};
|
|
|
|
|
case 'Radarr':
|
|
|
|
|
logInformation('radarr');
|
|
|
|
|
return {
|
|
|
|
|
type: 'radarr',
|
|
|
|
|
properties: [
|
|
|
|
|
{
|
|
|
|
|
field: 'apiKey',
|
|
|
|
|
isDefined: oldService.apiKey !== undefined,
|
|
|
|
|
type: 'private',
|
|
|
|
|
value: oldService.apiKey,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
};
|
|
|
|
|
case 'Readarr':
|
|
|
|
|
logInformation('readarr');
|
|
|
|
|
return {
|
|
|
|
|
type: 'readarr',
|
|
|
|
|
properties: [
|
|
|
|
|
{
|
|
|
|
|
field: 'apiKey',
|
|
|
|
|
isDefined: oldService.apiKey !== undefined,
|
|
|
|
|
type: 'private',
|
|
|
|
|
value: oldService.apiKey,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
};
|
|
|
|
|
case 'Sabnzbd':
|
|
|
|
|
logInformation('sabnzbd');
|
|
|
|
|
return {
|
|
|
|
|
type: 'sabnzbd',
|
|
|
|
|
properties: [
|
|
|
|
|
{
|
|
|
|
|
field: 'apiKey',
|
|
|
|
|
isDefined: oldService.apiKey !== undefined,
|
|
|
|
|
type: 'private',
|
|
|
|
|
value: oldService.apiKey,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
};
|
|
|
|
|
case 'Sonarr':
|
|
|
|
|
logInformation('sonarr');
|
|
|
|
|
return {
|
|
|
|
|
type: 'sonarr',
|
|
|
|
|
properties: [
|
|
|
|
|
{
|
|
|
|
|
field: 'apiKey',
|
|
|
|
|
isDefined: oldService.apiKey !== undefined,
|
|
|
|
|
type: 'private',
|
|
|
|
|
value: oldService.apiKey,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
};
|
|
|
|
|
case 'NZBGet':
|
|
|
|
|
logInformation('nzbGet');
|
|
|
|
|
return {
|
|
|
|
|
type: 'nzbGet',
|
|
|
|
|
properties: [
|
|
|
|
|
{
|
|
|
|
|
field: 'username',
|
|
|
|
|
isDefined: oldService.username !== undefined,
|
|
|
|
|
type: 'private',
|
|
|
|
|
value: oldService.username,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
field: 'password',
|
|
|
|
|
isDefined: oldService.password !== undefined,
|
|
|
|
|
type: 'private',
|
|
|
|
|
value: oldService.password,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
};
|
|
|
|
|
case 'qBittorrent':
|
|
|
|
|
logInformation('qBittorrent');
|
|
|
|
|
return {
|
|
|
|
|
type: 'qBittorrent',
|
|
|
|
|
properties: [
|
|
|
|
|
{
|
|
|
|
|
field: 'username',
|
|
|
|
|
isDefined: oldService.username !== undefined,
|
|
|
|
|
type: 'private',
|
|
|
|
|
value: oldService.username,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
field: 'password',
|
|
|
|
|
isDefined: oldService.password !== undefined,
|
|
|
|
|
type: 'private',
|
|
|
|
|
value: oldService.password,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
};
|
|
|
|
|
case 'Transmission':
|
|
|
|
|
logInformation('transmission');
|
|
|
|
|
return {
|
|
|
|
|
type: 'transmission',
|
|
|
|
|
properties: [
|
|
|
|
|
{
|
|
|
|
|
field: 'username',
|
|
|
|
|
isDefined: oldService.username !== undefined,
|
|
|
|
|
type: 'private',
|
|
|
|
|
value: oldService.username,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
field: 'password',
|
|
|
|
|
isDefined: oldService.password !== undefined,
|
|
|
|
|
type: 'private',
|
|
|
|
|
value: oldService.password,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
};
|
2023-01-08 12:47:06 +09:00
|
|
|
case 'Other':
|
|
|
|
|
return {
|
|
|
|
|
type: null,
|
|
|
|
|
properties: [],
|
|
|
|
|
};
|
2023-01-07 20:18:53 +01:00
|
|
|
default:
|
|
|
|
|
Consola.warn(
|
|
|
|
|
`Integration type of service ${oldService.name} could not be mapped to new integration type definition`
|
|
|
|
|
);
|
|
|
|
|
return {
|
|
|
|
|
type: null,
|
|
|
|
|
properties: [],
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
};
|