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({
|
||||
initialValues: {
|
||||
id: props.id ?? Date.now(),
|
||||
id: props.id ?? crypto.randomUUID(),
|
||||
type: props.type ?? 'Other',
|
||||
name: props.name ?? '',
|
||||
icon: props.icon ?? '/favicon.svg',
|
||||
|
||||
@@ -7,6 +7,7 @@ import { useRouter } from 'next/router';
|
||||
import { setCookies } from 'cookies-next';
|
||||
import { useConfig } from '../../tools/state';
|
||||
import { Config } from '../../tools/types';
|
||||
import { migrateToIdConfig } from '../../tools/migrate';
|
||||
|
||||
function getIconColor(status: DropzoneStatus, theme: MantineTheme) {
|
||||
return status.accepted
|
||||
@@ -84,7 +85,8 @@ export default function LoadConfigComponent(props: any) {
|
||||
message: undefined,
|
||||
});
|
||||
setCookies('config-name', newConfig.name, { maxAge: 60 * 60 * 24 * 30 });
|
||||
setConfig(newConfig);
|
||||
const migratedConfig = migrateToIdConfig(newConfig);
|
||||
setConfig(migratedConfig);
|
||||
});
|
||||
}}
|
||||
accept={['application/json']}
|
||||
|
||||
@@ -7,6 +7,7 @@ import AppShelf from '../components/AppShelf/AppShelf';
|
||||
import LoadConfigComponent from '../components/Config/LoadConfig';
|
||||
import { Config } from '../tools/types';
|
||||
import { useConfig } from '../tools/state';
|
||||
import { migrateToIdConfig } from '../tools/migrate';
|
||||
|
||||
export async function getServerSideProps({
|
||||
req,
|
||||
@@ -48,7 +49,8 @@ export default function HomePage(props: any) {
|
||||
const { config: initialConfig }: { config: Config } = props;
|
||||
const { config, loadConfig, setConfig, getConfigs } = useConfig();
|
||||
useEffect(() => {
|
||||
setConfig(initialConfig);
|
||||
const migratedConfig = migrateToIdConfig(initialConfig);
|
||||
setConfig(migratedConfig);
|
||||
}, [initialConfig]);
|
||||
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';
|
||||
|
||||
export interface serviceItem {
|
||||
id: number;
|
||||
id: string;
|
||||
name: string;
|
||||
type: string;
|
||||
url: string;
|
||||
|
||||
Reference in New Issue
Block a user