Work in progress atmosphere stats viewer
810 B
39 lines
1import { query } from '$app/server';
2
3async function grab<T>(path: string) {
4 const url = new URL('http://127.0.0.1:7712');
5 url.pathname = path;
6
7 const response = await fetch(url);
8 if (!response.ok) throw new Error('broked');
9
10 const data = await response.json();
11 return data as T;
12}
13
14export interface Counts {
15 operations: number;
16 dids: number;
17}
18
19export const getCounts = query.live(async function* () {
20 while (true) {
21 yield await grab<Counts>('/v0/counts');
22 await new Promise((resolve) => setTimeout(resolve, 10_000));
23 }
24});
25
26interface CountsGraphed {
27 date: string;
28 dids: number;
29 operations: number;
30}
31
32export const getCountsGraph = query(async () => {
33 const raw = await grab<CountsGraphed[]>('/v0/counts/history');
34
35 return raw.map((c) => {
36 c.date = new Date(c.date);
37 return c;
38 });
39});