mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-11 16:05:47 +01:00
🚨 Fix build error in config upload
This commit is contained in:
@@ -2,12 +2,9 @@ import { Group, Stack, Text, Title, useMantineTheme } from '@mantine/core';
|
|||||||
import { Dropzone } from '@mantine/dropzone';
|
import { Dropzone } from '@mantine/dropzone';
|
||||||
import { showNotification } from '@mantine/notifications';
|
import { showNotification } from '@mantine/notifications';
|
||||||
import { IconCheck as Check, IconPhoto, IconUpload, IconX, IconX as X } from '@tabler/icons';
|
import { IconCheck as Check, IconPhoto, IconUpload, IconX, IconX as X } from '@tabler/icons';
|
||||||
import Consola from 'consola';
|
|
||||||
import { setCookie } from 'cookies-next';
|
import { setCookie } from 'cookies-next';
|
||||||
import { useTranslation } from 'next-i18next';
|
import { useTranslation } from 'next-i18next';
|
||||||
import { useConfigStore } from '../../config/store';
|
import { useConfigStore } from '../../config/store';
|
||||||
import { migrateConfig } from '../../tools/config/migrateConfig';
|
|
||||||
import { Config } from '../../tools/types';
|
|
||||||
import { ConfigType } from '../../types/config';
|
import { ConfigType } from '../../types/config';
|
||||||
|
|
||||||
export const LoadConfigComponent = () => {
|
export const LoadConfigComponent = () => {
|
||||||
@@ -34,15 +31,7 @@ export const LoadConfigComponent = () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let newConfig: ConfigType = JSON.parse(fileText);
|
const newConfig: ConfigType = JSON.parse(fileText);
|
||||||
|
|
||||||
if (!newConfig.schemaVersion) {
|
|
||||||
Consola.warn(
|
|
||||||
'a legacy configuration schema was deteced and migrated to the current schema'
|
|
||||||
);
|
|
||||||
const oldConfig = JSON.parse(fileText) as Config;
|
|
||||||
newConfig = migrateConfig(oldConfig);
|
|
||||||
}
|
|
||||||
|
|
||||||
await addConfig(fileName, newConfig, true);
|
await addConfig(fileName, newConfig, true);
|
||||||
showNotification({
|
showNotification({
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import { ConfigType } from '../../types/config';
|
import { BackendConfigType } from '../../types/config';
|
||||||
import { Config } from '../types';
|
import { Config } from '../types';
|
||||||
import { migrateConfig } from './migrateConfig';
|
import { migrateConfig } from './migrateConfig';
|
||||||
|
|
||||||
export function backendMigrateConfig(config: Config, name: string): ConfigType {
|
export function backendMigrateConfig(config: Config, name: string): BackendConfigType {
|
||||||
const migratedConfig = migrateConfig(config);
|
const migratedConfig = migrateConfig(config);
|
||||||
|
|
||||||
// Make a backup of the old file ./data/configs/${name}.json
|
// Make a backup of the old file ./data/configs/${name}.json
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
import Consola from 'consola';
|
import Consola from 'consola';
|
||||||
import { v4 as uuidv4 } from 'uuid';
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
import { AppIntegrationType, AppType, IntegrationType } from '../../types/app';
|
import { ConfigAppIntegrationType, ConfigAppType, IntegrationType } from '../../types/app';
|
||||||
import { AreaType } from '../../types/area';
|
import { AreaType } from '../../types/area';
|
||||||
import { CategoryType } from '../../types/category';
|
import { CategoryType } from '../../types/category';
|
||||||
import { BackendConfigType, ConfigType } from '../../types/config';
|
import { BackendConfigType } from '../../types/config';
|
||||||
import { SearchEngineCommonSettingsType } from '../../types/settings';
|
import { SearchEngineCommonSettingsType } from '../../types/settings';
|
||||||
import { ITorrent } from '../../widgets/torrent/TorrentTile';
|
|
||||||
import { ICalendarWidget } from '../../widgets/calendar/CalendarTile';
|
import { ICalendarWidget } from '../../widgets/calendar/CalendarTile';
|
||||||
import { IDashDotTile } from '../../widgets/dashDot/DashDotTile';
|
import { IDashDotTile } from '../../widgets/dashDot/DashDotTile';
|
||||||
import { IDateWidget } from '../../widgets/date/DateTile';
|
import { IDateWidget } from '../../widgets/date/DateTile';
|
||||||
|
import { ITorrent } from '../../widgets/torrent/TorrentTile';
|
||||||
import { ITorrentNetworkTraffic } from '../../widgets/torrentNetworkTraffic/TorrentNetworkTrafficTile';
|
import { ITorrentNetworkTraffic } from '../../widgets/torrentNetworkTraffic/TorrentNetworkTrafficTile';
|
||||||
import { IUsenetWidget } from '../../widgets/useNet/UseNetTile';
|
import { IUsenetWidget } from '../../widgets/useNet/UseNetTile';
|
||||||
import { IWeatherWidget } from '../../widgets/weather/WeatherTile';
|
import { IWeatherWidget } from '../../widgets/weather/WeatherTile';
|
||||||
@@ -16,7 +16,7 @@ import { IWidget } from '../../widgets/widgets';
|
|||||||
import { Config, serviceItem } from '../types';
|
import { Config, serviceItem } from '../types';
|
||||||
|
|
||||||
export function migrateConfig(config: Config): BackendConfigType {
|
export function migrateConfig(config: Config): BackendConfigType {
|
||||||
const newConfig: ConfigType = {
|
const newConfig: BackendConfigType = {
|
||||||
schemaVersion: 1,
|
schemaVersion: 1,
|
||||||
configProperties: {
|
configProperties: {
|
||||||
name: config.name ?? 'default',
|
name: config.name ?? 'default',
|
||||||
@@ -78,6 +78,8 @@ export function migrateConfig(config: Config): BackendConfigType {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Consola.info('Migrator converted a configuration with the old schema to the new schema');
|
||||||
|
|
||||||
return newConfig;
|
return newConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,7 +122,7 @@ const migrateSearchEngine = (config: Config): SearchEngineCommonSettingsType =>
|
|||||||
};
|
};
|
||||||
|
|
||||||
const getConfigAndCreateIfNotExsists = (
|
const getConfigAndCreateIfNotExsists = (
|
||||||
config: ConfigType,
|
config: BackendConfigType,
|
||||||
categoryName: string
|
categoryName: string
|
||||||
): CategoryType | null => {
|
): CategoryType | null => {
|
||||||
const foundCategory = config.categories.find((c) => c.name === categoryName);
|
const foundCategory = config.categories.find((c) => c.name === categoryName);
|
||||||
@@ -147,7 +149,7 @@ const getConfigAndCreateIfNotExsists = (
|
|||||||
return category;
|
return category;
|
||||||
};
|
};
|
||||||
|
|
||||||
const migrateService = (oldService: serviceItem, areaType: AreaType): AppType => ({
|
const migrateService = (oldService: serviceItem, areaType: AreaType): ConfigAppType => ({
|
||||||
id: uuidv4(),
|
id: uuidv4(),
|
||||||
name: oldService.name,
|
name: oldService.name,
|
||||||
url: oldService.url,
|
url: oldService.url,
|
||||||
@@ -301,7 +303,7 @@ const migrateIcon = (iconUrl: string) => {
|
|||||||
return iconUrl;
|
return iconUrl;
|
||||||
};
|
};
|
||||||
|
|
||||||
const migrateIntegration = (oldService: serviceItem): AppIntegrationType => {
|
const migrateIntegration = (oldService: serviceItem): ConfigAppIntegrationType => {
|
||||||
const logInformation = (newType: IntegrationType) => {
|
const logInformation = (newType: IntegrationType) => {
|
||||||
Consola.info(`Migrated integration ${oldService.type} to the new type ${newType}`);
|
Consola.info(`Migrated integration ${oldService.type} to the new type ${newType}`);
|
||||||
};
|
};
|
||||||
@@ -313,7 +315,6 @@ const migrateIntegration = (oldService: serviceItem): AppIntegrationType => {
|
|||||||
properties: [
|
properties: [
|
||||||
{
|
{
|
||||||
field: 'password',
|
field: 'password',
|
||||||
isDefined: oldService.password !== undefined,
|
|
||||||
type: 'private',
|
type: 'private',
|
||||||
value: oldService.password,
|
value: oldService.password,
|
||||||
},
|
},
|
||||||
@@ -326,7 +327,6 @@ const migrateIntegration = (oldService: serviceItem): AppIntegrationType => {
|
|||||||
properties: [
|
properties: [
|
||||||
{
|
{
|
||||||
field: 'apiKey',
|
field: 'apiKey',
|
||||||
isDefined: oldService.apiKey !== undefined,
|
|
||||||
type: 'private',
|
type: 'private',
|
||||||
value: oldService.apiKey,
|
value: oldService.apiKey,
|
||||||
},
|
},
|
||||||
@@ -339,7 +339,6 @@ const migrateIntegration = (oldService: serviceItem): AppIntegrationType => {
|
|||||||
properties: [
|
properties: [
|
||||||
{
|
{
|
||||||
field: 'apiKey',
|
field: 'apiKey',
|
||||||
isDefined: oldService.apiKey !== undefined,
|
|
||||||
type: 'private',
|
type: 'private',
|
||||||
value: oldService.apiKey,
|
value: oldService.apiKey,
|
||||||
},
|
},
|
||||||
@@ -352,7 +351,6 @@ const migrateIntegration = (oldService: serviceItem): AppIntegrationType => {
|
|||||||
properties: [
|
properties: [
|
||||||
{
|
{
|
||||||
field: 'apiKey',
|
field: 'apiKey',
|
||||||
isDefined: oldService.apiKey !== undefined,
|
|
||||||
type: 'private',
|
type: 'private',
|
||||||
value: oldService.apiKey,
|
value: oldService.apiKey,
|
||||||
},
|
},
|
||||||
@@ -365,7 +363,6 @@ const migrateIntegration = (oldService: serviceItem): AppIntegrationType => {
|
|||||||
properties: [
|
properties: [
|
||||||
{
|
{
|
||||||
field: 'apiKey',
|
field: 'apiKey',
|
||||||
isDefined: oldService.apiKey !== undefined,
|
|
||||||
type: 'private',
|
type: 'private',
|
||||||
value: oldService.apiKey,
|
value: oldService.apiKey,
|
||||||
},
|
},
|
||||||
@@ -378,7 +375,6 @@ const migrateIntegration = (oldService: serviceItem): AppIntegrationType => {
|
|||||||
properties: [
|
properties: [
|
||||||
{
|
{
|
||||||
field: 'apiKey',
|
field: 'apiKey',
|
||||||
isDefined: oldService.apiKey !== undefined,
|
|
||||||
type: 'private',
|
type: 'private',
|
||||||
value: oldService.apiKey,
|
value: oldService.apiKey,
|
||||||
},
|
},
|
||||||
@@ -391,7 +387,6 @@ const migrateIntegration = (oldService: serviceItem): AppIntegrationType => {
|
|||||||
properties: [
|
properties: [
|
||||||
{
|
{
|
||||||
field: 'apiKey',
|
field: 'apiKey',
|
||||||
isDefined: oldService.apiKey !== undefined,
|
|
||||||
type: 'private',
|
type: 'private',
|
||||||
value: oldService.apiKey,
|
value: oldService.apiKey,
|
||||||
},
|
},
|
||||||
@@ -404,7 +399,6 @@ const migrateIntegration = (oldService: serviceItem): AppIntegrationType => {
|
|||||||
properties: [
|
properties: [
|
||||||
{
|
{
|
||||||
field: 'apiKey',
|
field: 'apiKey',
|
||||||
isDefined: oldService.apiKey !== undefined,
|
|
||||||
type: 'private',
|
type: 'private',
|
||||||
value: oldService.apiKey,
|
value: oldService.apiKey,
|
||||||
},
|
},
|
||||||
@@ -417,13 +411,11 @@ const migrateIntegration = (oldService: serviceItem): AppIntegrationType => {
|
|||||||
properties: [
|
properties: [
|
||||||
{
|
{
|
||||||
field: 'username',
|
field: 'username',
|
||||||
isDefined: oldService.username !== undefined,
|
|
||||||
type: 'private',
|
type: 'private',
|
||||||
value: oldService.username,
|
value: oldService.username,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'password',
|
field: 'password',
|
||||||
isDefined: oldService.password !== undefined,
|
|
||||||
type: 'private',
|
type: 'private',
|
||||||
value: oldService.password,
|
value: oldService.password,
|
||||||
},
|
},
|
||||||
@@ -436,13 +428,11 @@ const migrateIntegration = (oldService: serviceItem): AppIntegrationType => {
|
|||||||
properties: [
|
properties: [
|
||||||
{
|
{
|
||||||
field: 'username',
|
field: 'username',
|
||||||
isDefined: oldService.username !== undefined,
|
|
||||||
type: 'private',
|
type: 'private',
|
||||||
value: oldService.username,
|
value: oldService.username,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'password',
|
field: 'password',
|
||||||
isDefined: oldService.password !== undefined,
|
|
||||||
type: 'private',
|
type: 'private',
|
||||||
value: oldService.password,
|
value: oldService.password,
|
||||||
},
|
},
|
||||||
@@ -455,13 +445,11 @@ const migrateIntegration = (oldService: serviceItem): AppIntegrationType => {
|
|||||||
properties: [
|
properties: [
|
||||||
{
|
{
|
||||||
field: 'username',
|
field: 'username',
|
||||||
isDefined: oldService.username !== undefined,
|
|
||||||
type: 'private',
|
type: 'private',
|
||||||
value: oldService.username,
|
value: oldService.username,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'password',
|
field: 'password',
|
||||||
isDefined: oldService.password !== undefined,
|
|
||||||
type: 'private',
|
type: 'private',
|
||||||
value: oldService.password,
|
value: oldService.password,
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user