Makes healthcheck data a server polling thing.

This commit is contained in:
2023-09-21 10:57:37 +02:00
parent e0be278630
commit 3311594f1e
7 changed files with 96 additions and 83 deletions

View File

@@ -1,11 +1,21 @@
import { type ServiceHandler } from '../service';
import type { ServiceConfig } from '$lib/config';
import { type ServiceData, type ServiceHandler } from '../service';
export const handle: ServiceHandler = ({ fetch, config }) => {
const url = config.url + '/api.php?summaryRaw&auth=' + config.api_token;
return {
logo: 'https://cdn.rawgit.com/pi-hole/graphics/master/Vortex/Vortex.svg',
raw: fetch(url).then((raw) => raw.json()),
url: url
export const handle: ServiceHandler = async (config: ServiceConfig) => {
const res: ServiceData = {
logo: 'https://cdn.rawgit.com/pi-hole/graphics/master/Vortex/Vortex.svg'
};
try {
const resp: Response = await fetch(
config.url + '/api.php?summaryRaw&auth=' + config.api_token
);
res.status = resp.ok ? 'online' : 'offline';
res.raw = resp.json();
} catch (error) {
res.status = undefined;
console.warn('could not fetch pihole status: ' + error);
}
return res;
};