28 lines
776 B
TypeScript
28 lines
776 B
TypeScript
import type { ServiceConfig } from '$lib/config';
|
|
import { type ServiceData, type ServiceHandler } from '../service';
|
|
|
|
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';
|
|
const raw = await resp.json();
|
|
res.data = {
|
|
queries_today: raw.dns_queries_today,
|
|
ads_percentage: raw.ads_percentage_today,
|
|
status: raw.status,
|
|
client: raw.unique_clients
|
|
};
|
|
} catch (error) {
|
|
res.status = 'offline';
|
|
console.warn('could not fetch pihole status: ' + error);
|
|
}
|
|
|
|
return res;
|
|
};
|