mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-08 14:35:49 +01:00
@@ -4,6 +4,7 @@ import { Text, AspectRatio, Card, Image, Center, Grid, createStyles } from '@man
|
|||||||
import { useConfig } from '../../tools/state';
|
import { useConfig } from '../../tools/state';
|
||||||
import { serviceItem } from '../../tools/types';
|
import { serviceItem } from '../../tools/types';
|
||||||
import AppShelfMenu from './AppShelfMenu';
|
import AppShelfMenu from './AppShelfMenu';
|
||||||
|
import PingComponent from '../modules/ping/PingModule';
|
||||||
|
|
||||||
const useStyles = createStyles((theme) => ({
|
const useStyles = createStyles((theme) => ({
|
||||||
item: {
|
item: {
|
||||||
@@ -89,6 +90,7 @@ export function AppShelfItem(props: any) {
|
|||||||
/>
|
/>
|
||||||
</motion.i>
|
</motion.i>
|
||||||
</AspectRatio>
|
</AspectRatio>
|
||||||
|
<PingComponent url={service.url} />
|
||||||
</Card.Section>
|
</Card.Section>
|
||||||
</Center>
|
</Center>
|
||||||
</Card>
|
</Card>
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
export * from './date';
|
export * from './date';
|
||||||
export * from './calendar';
|
export * from './calendar';
|
||||||
export * from './search';
|
export * from './search';
|
||||||
|
export * from './ping';
|
||||||
|
|||||||
15
src/components/modules/ping/PingModule.story.tsx
Normal file
15
src/components/modules/ping/PingModule.story.tsx
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import { serviceItem } from '../../../tools/types';
|
||||||
|
import PingComponent from './PingModule';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
title: 'Modules/Search bar',
|
||||||
|
};
|
||||||
|
|
||||||
|
const service: serviceItem = {
|
||||||
|
type: 'Other',
|
||||||
|
name: 'YouTube',
|
||||||
|
icon: 'https://cdn.jsdelivr.net/gh/walkxhub/dashboard-icons/png/youtube.png',
|
||||||
|
url: 'https://youtube.com/',
|
||||||
|
};
|
||||||
|
|
||||||
|
export const Default = (args: any) => <PingComponent service={service} />;
|
||||||
51
src/components/modules/ping/PingModule.tsx
Normal file
51
src/components/modules/ping/PingModule.tsx
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
import { Indicator, Tooltip } from '@mantine/core';
|
||||||
|
import axios from 'axios';
|
||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import { Plug } from 'tabler-icons-react';
|
||||||
|
import { useConfig } from '../../../tools/state';
|
||||||
|
import { IModule } from '../modules';
|
||||||
|
|
||||||
|
export const PingModule: IModule = {
|
||||||
|
title: 'Ping Services',
|
||||||
|
description: 'Pings your services and shows their status as an indicator',
|
||||||
|
icon: Plug,
|
||||||
|
component: PingComponent,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function PingComponent(props: any) {
|
||||||
|
type State = 'loading' | 'down' | 'online';
|
||||||
|
const { config } = useConfig();
|
||||||
|
|
||||||
|
const { url }: { url: string } = props;
|
||||||
|
const [isOnline, setOnline] = useState<State>('loading');
|
||||||
|
useEffect(() => {
|
||||||
|
if (!config.settings.enabledModules.includes('Ping Services')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
axios
|
||||||
|
.get('/api/modules/ping', { params: { url } })
|
||||||
|
.then(() => {
|
||||||
|
setOnline('online');
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
setOnline('down');
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
if (!config.settings.enabledModules.includes('Ping Services')) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<Tooltip
|
||||||
|
radius="lg"
|
||||||
|
style={{ position: 'absolute', bottom: 20, right: 20 }}
|
||||||
|
label={isOnline === 'loading' ? 'Loading...' : isOnline === 'online' ? 'Online' : 'Offline'}
|
||||||
|
>
|
||||||
|
<Indicator
|
||||||
|
size={13}
|
||||||
|
color={isOnline === 'online' ? 'green' : isOnline === 'down' ? 'red' : 'yellow'}
|
||||||
|
>
|
||||||
|
{null}
|
||||||
|
</Indicator>
|
||||||
|
</Tooltip>
|
||||||
|
);
|
||||||
|
}
|
||||||
1
src/components/modules/ping/index.ts
Normal file
1
src/components/modules/ping/index.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export { PingModule } from './PingModule';
|
||||||
8
src/pages/[slug].tsx
Normal file
8
src/pages/[slug].tsx
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import { Title } from '@mantine/core';
|
||||||
|
import { useRouter } from 'next/router';
|
||||||
|
|
||||||
|
export default function SlugPage(props: any) {
|
||||||
|
const router = useRouter();
|
||||||
|
const { slug } = router.query;
|
||||||
|
return <Title>ok</Title>;
|
||||||
|
}
|
||||||
29
src/pages/api/modules/ping.ts
Normal file
29
src/pages/api/modules/ping.ts
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import axios from 'axios';
|
||||||
|
import { NextApiRequest, NextApiResponse } from 'next';
|
||||||
|
|
||||||
|
async function Get(req: NextApiRequest, res: NextApiResponse) {
|
||||||
|
// Parse req.body as a ServiceItem
|
||||||
|
const { url } = req.query;
|
||||||
|
await axios
|
||||||
|
.get(url as string)
|
||||||
|
.then((response) => {
|
||||||
|
res.status(200).json(response.data);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
res.status(500).json(error);
|
||||||
|
});
|
||||||
|
// // Make a request to the URL
|
||||||
|
// const response = await axios.get(url);
|
||||||
|
// // Return the response
|
||||||
|
}
|
||||||
|
|
||||||
|
export default async (req: NextApiRequest, res: NextApiResponse) => {
|
||||||
|
// Filter out if the reuqest is a POST or a GET
|
||||||
|
if (req.method === 'GET') {
|
||||||
|
return Get(req, res);
|
||||||
|
}
|
||||||
|
return res.status(405).json({
|
||||||
|
statusCode: 405,
|
||||||
|
message: 'Method not allowed',
|
||||||
|
});
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user