mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-11 07:55:52 +01:00
🚑️ Ping array (#823)
This commit is contained in:
@@ -96,6 +96,7 @@ export const AvailableElementTypes = ({
|
||||
network: {
|
||||
enabledStatusChecker: true,
|
||||
statusCodes: ['200'],
|
||||
okStatus: [200],
|
||||
},
|
||||
behaviour: {
|
||||
isOpeningNewTab: true,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Indicator, Tooltip } from '@mantine/core';
|
||||
import Consola from 'consola';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { motion } from 'framer-motion';
|
||||
import { useTranslation } from 'next-i18next';
|
||||
@@ -19,7 +20,7 @@ export const AppPing = ({ app }: AppPingProps) => {
|
||||
queryKey: ['ping', { id: app.id, name: app.name }],
|
||||
queryFn: async () => {
|
||||
const response = await fetch(`/api/modules/ping?url=${encodeURI(app.url)}`);
|
||||
const isOk = app.network.statusCodes.includes(response.status.toString());
|
||||
const isOk = getIsOk(app, response.status);
|
||||
return {
|
||||
status: response.status,
|
||||
state: isOk ? 'online' : 'down',
|
||||
@@ -60,3 +61,12 @@ export const AppPing = ({ app }: AppPingProps) => {
|
||||
</motion.div>
|
||||
);
|
||||
};
|
||||
|
||||
const getIsOk = (app: AppType, status: number) => {
|
||||
if (app.network.okStatus === undefined || app.network.statusCodes.length >= 1) {
|
||||
Consola.log('Using new status codes');
|
||||
return app.network.statusCodes.includes(status.toString());
|
||||
}
|
||||
Consola.warn('Using deprecated okStatus');
|
||||
return app.network.okStatus.includes(status);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user