mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-10 23:45:48 +01:00
✨ Match config with URL typed
Homarr will now match a config with the URL used or return a 404 if not found
This commit is contained in:
@@ -32,8 +32,9 @@ export default function CalendarComponent(props: any) {
|
|||||||
const radarrService = filtered.filter((service) => service.type === 'Radarr').at(0);
|
const radarrService = filtered.filter((service) => service.type === 'Radarr').at(0);
|
||||||
const nextMonth = new Date(new Date().setMonth(new Date().getMonth() + 2)).toISOString();
|
const nextMonth = new Date(new Date().setMonth(new Date().getMonth() + 2)).toISOString();
|
||||||
if (sonarrService && sonarrService.apiKey) {
|
if (sonarrService && sonarrService.apiKey) {
|
||||||
|
const baseUrl = new URL(sonarrService.url).origin;
|
||||||
fetch(
|
fetch(
|
||||||
`${sonarrService?.url}api/calendar?apikey=${sonarrService?.apiKey}&end=${nextMonth}`
|
`${baseUrl}api/calendar?apikey=${sonarrService?.apiKey}&end=${nextMonth}`
|
||||||
).then((response) => {
|
).then((response) => {
|
||||||
response.ok &&
|
response.ok &&
|
||||||
response.json().then((data) => {
|
response.json().then((data) => {
|
||||||
@@ -50,9 +51,9 @@ export default function CalendarComponent(props: any) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (radarrService && radarrService.apiKey) {
|
if (radarrService && radarrService.apiKey) {
|
||||||
fetch(
|
const baseUrl = new URL(radarrService.url).origin;
|
||||||
`${radarrService?.url}api/v3/calendar?apikey=${radarrService?.apiKey}&end=${nextMonth}`
|
fetch(`${baseUrl}api/v3/calendar?apikey=${radarrService?.apiKey}&end=${nextMonth}`).then(
|
||||||
).then((response) => {
|
(response) => {
|
||||||
response.ok &&
|
response.ok &&
|
||||||
response.json().then((data) => {
|
response.json().then((data) => {
|
||||||
setRadarrMedias(data);
|
setRadarrMedias(data);
|
||||||
@@ -65,7 +66,8 @@ export default function CalendarComponent(props: any) {
|
|||||||
message: `Loaded ${data.length} releases`,
|
message: `Loaded ${data.length} releases`,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}, [config.services]);
|
}, [config.services]);
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,54 @@
|
|||||||
import { Title } from '@mantine/core';
|
import { GetServerSidePropsContext } from 'next';
|
||||||
import { useRouter } from 'next/router';
|
import path from 'path';
|
||||||
|
import fs from 'fs';
|
||||||
|
import { useEffect } from 'react';
|
||||||
|
import AppShelf from '../components/AppShelf/AppShelf';
|
||||||
|
import LoadConfigComponent from '../components/Config/LoadConfig';
|
||||||
|
import { Config } from '../tools/types';
|
||||||
|
import { useConfig } from '../tools/state';
|
||||||
|
|
||||||
export default function SlugPage(props: any) {
|
export async function getServerSideProps(
|
||||||
const router = useRouter();
|
context: GetServerSidePropsContext
|
||||||
const { slug } = router.query;
|
): Promise<{ props: { config: Config } }> {
|
||||||
return <Title>ok</Title>;
|
const configByUrl = context.query.slug;
|
||||||
|
const configPath = path.join(process.cwd(), 'data/configs', `${configByUrl}.json`);
|
||||||
|
const configExists = fs.existsSync(configPath);
|
||||||
|
if (!configExists) {
|
||||||
|
// Redirect to 404
|
||||||
|
context.res.writeHead(301, { Location: '/404' });
|
||||||
|
context.res.end();
|
||||||
|
return {
|
||||||
|
props: {
|
||||||
|
config: {
|
||||||
|
name: '',
|
||||||
|
services: [],
|
||||||
|
settings: {
|
||||||
|
enabledModules: [],
|
||||||
|
searchUrl: 'https://www.google.com/search?q=',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const config = fs.readFileSync(configPath, 'utf8');
|
||||||
|
// Print loaded config
|
||||||
|
return {
|
||||||
|
props: {
|
||||||
|
config: JSON.parse(config),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function HomePage(props: any) {
|
||||||
|
const { config: initialConfig }: { config: Config } = props;
|
||||||
|
const { setConfig } = useConfig();
|
||||||
|
useEffect(() => {
|
||||||
|
setConfig(initialConfig);
|
||||||
|
}, [initialConfig]);
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<AppShelf />
|
||||||
|
<LoadConfigComponent />
|
||||||
|
</>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user