mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-10 07:25:48 +01:00
🚑 Fix UUID by using crypto
This commit is contained in:
@@ -122,7 +122,7 @@ export function AddAppShelfItemForm(props: { setOpened: (b: boolean) => void } &
|
|||||||
|
|
||||||
const form = useForm({
|
const form = useForm({
|
||||||
initialValues: {
|
initialValues: {
|
||||||
id: props.id ?? Date.now(),
|
id: props.id ?? crypto.randomUUID(),
|
||||||
type: props.type ?? 'Other',
|
type: props.type ?? 'Other',
|
||||||
name: props.name ?? '',
|
name: props.name ?? '',
|
||||||
icon: props.icon ?? '/favicon.svg',
|
icon: props.icon ?? '/favicon.svg',
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { useRouter } from 'next/router';
|
|||||||
import { setCookies } from 'cookies-next';
|
import { setCookies } from 'cookies-next';
|
||||||
import { useConfig } from '../../tools/state';
|
import { useConfig } from '../../tools/state';
|
||||||
import { Config } from '../../tools/types';
|
import { Config } from '../../tools/types';
|
||||||
|
import { migrateToIdConfig } from '../../tools/migrate';
|
||||||
|
|
||||||
function getIconColor(status: DropzoneStatus, theme: MantineTheme) {
|
function getIconColor(status: DropzoneStatus, theme: MantineTheme) {
|
||||||
return status.accepted
|
return status.accepted
|
||||||
@@ -84,7 +85,8 @@ export default function LoadConfigComponent(props: any) {
|
|||||||
message: undefined,
|
message: undefined,
|
||||||
});
|
});
|
||||||
setCookies('config-name', newConfig.name, { maxAge: 60 * 60 * 24 * 30 });
|
setCookies('config-name', newConfig.name, { maxAge: 60 * 60 * 24 * 30 });
|
||||||
setConfig(newConfig);
|
const migratedConfig = migrateToIdConfig(newConfig);
|
||||||
|
setConfig(migratedConfig);
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
accept={['application/json']}
|
accept={['application/json']}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import AppShelf from '../components/AppShelf/AppShelf';
|
|||||||
import LoadConfigComponent from '../components/Config/LoadConfig';
|
import LoadConfigComponent from '../components/Config/LoadConfig';
|
||||||
import { Config } from '../tools/types';
|
import { Config } from '../tools/types';
|
||||||
import { useConfig } from '../tools/state';
|
import { useConfig } from '../tools/state';
|
||||||
|
import { migrateToIdConfig } from '../tools/migrate';
|
||||||
|
|
||||||
export async function getServerSideProps({
|
export async function getServerSideProps({
|
||||||
req,
|
req,
|
||||||
@@ -48,7 +49,8 @@ export default function HomePage(props: any) {
|
|||||||
const { config: initialConfig }: { config: Config } = props;
|
const { config: initialConfig }: { config: Config } = props;
|
||||||
const { config, loadConfig, setConfig, getConfigs } = useConfig();
|
const { config, loadConfig, setConfig, getConfigs } = useConfig();
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setConfig(initialConfig);
|
const migratedConfig = migrateToIdConfig(initialConfig);
|
||||||
|
setConfig(migratedConfig);
|
||||||
}, [initialConfig]);
|
}, [initialConfig]);
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|||||||
13
src/tools/migrate.ts
Normal file
13
src/tools/migrate.ts
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import { Config } from './types';
|
||||||
|
|
||||||
|
export function migrateToIdConfig(config: Config): Config {
|
||||||
|
// Set the config and add an ID to all the services that don't have one
|
||||||
|
const services = config.services.map((service) => ({
|
||||||
|
...service,
|
||||||
|
id: service.id ?? crypto.randomUUID(),
|
||||||
|
}));
|
||||||
|
return {
|
||||||
|
...config,
|
||||||
|
services,
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -29,7 +29,7 @@ export type ServiceType =
|
|||||||
| 'Emby';
|
| 'Emby';
|
||||||
|
|
||||||
export interface serviceItem {
|
export interface serviceItem {
|
||||||
id: number;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
type: string;
|
type: string;
|
||||||
url: string;
|
url: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user