🚑️ Ping array (#823)

This commit is contained in:
Manuel
2023-04-21 10:21:34 +02:00
committed by GitHub
parent f4d936e3e5
commit 5a6c039f5b
6 changed files with 23 additions and 1 deletions

View File

@@ -96,6 +96,7 @@ export const AvailableElementTypes = ({
network: {
enabledStatusChecker: true,
statusCodes: ['200'],
okStatus: [200],
},
behaviour: {
isOpeningNewTab: true,

View File

@@ -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);
};