From abea3f1be9fd251cf85826d61bd109724209b549 Mon Sep 17 00:00:00 2001 From: Neshura Date: Thu, 4 Jan 2024 01:35:56 +0100 Subject: [PATCH] Add initial /servers route --- src/lib/components/ServerCard.svelte | 79 +++++++++++---------- src/lib/types/data-types.ts | 15 +++- src/routes/data/servers/+server.ts | 10 +++ src/routes/data/services/+server.ts | 2 +- src/routes/servers/+page.server.ts | 62 ++++++++++++++++ src/routes/servers/+page.svelte | 102 +++++++++++++++++++++++++++ static/data/servers.json | 37 +++++----- 7 files changed, 247 insertions(+), 60 deletions(-) diff --git a/src/lib/components/ServerCard.svelte b/src/lib/components/ServerCard.svelte index cc05270..2d06eef 100644 --- a/src/lib/components/ServerCard.svelte +++ b/src/lib/components/ServerCard.svelte @@ -4,14 +4,14 @@ import { OpenInNewWindow } from 'radix-icons-svelte'; import { quintInOut } from 'svelte/easing'; import { slide } from 'svelte/transition'; - import { IconType, type Service } from '$lib/types/data-types'; + import { IconType, type Server } from '$lib/types/data-types'; import { Skeleton } from '$lib/components/ui/skeleton'; import type { Heartbeat } from '$lib/types/uptime-kuma-types'; - let { service, icons, monitor } = $props<{ - service: Service; + let { server, icons, monitor } = $props<{ + server: Server; icons: Array; - monitor: Heartbeat; + monitor?: Heartbeat; }>(); let status = $state(4); @@ -24,32 +24,36 @@ let img_source: string = $state(''); - function checkForImage(service: Service) { - const rootSplit = service.icon.split('/'); + function checkForImage(server: Server) { + const rootSplit = server.icon.split('/'); const root = rootSplit[rootSplit.length - 1]; - if (icons.includes(`${root}.${service.iconType}`)) { - img_source = `${service.icon}.${service.iconType}`; + if (icons.includes(`${root}.${server.iconType}`)) { + img_source = `${server.icon}.${server.iconType}`; } else { img_source = ''; } } $effect(() => { + if (typeof server.id === 'undefined') { + status = 99; + } if (typeof monitor !== 'undefined') { status = monitor.status; } - if (icons.length != 0) { - const rootSplit = service.icon.split('/'); + if (icons.length != 0 && typeof server.icon !== "undefined") { + const rootSplit = server.icon.split('/'); const root = rootSplit[rootSplit.length - 1]; - if (service.iconType === IconType.SVG) { - checkForImage(service); - } else { - if (icons.includes(`${root}-36.${service.iconType}`)) { - img_source = `${service.icon}-36.${service.iconType}`; + if (server.iconType === IconType.SVG) { + checkForImage(server); + } + else { + if (icons.includes(`${root}-36.${server.iconType}`)) { + img_source = `${server.icon}-36.${server.iconType}`; } else { - checkForImage(service); + checkForImage(server); } } } @@ -58,15 +62,16 @@
@@ -75,22 +80,22 @@ on:mouseover={() => (hover.title = true)} on:mouseleave={() => (hover.title = false)} > - {#if service.icon} + {#if typeof server.icon !== "undefined"} {#if img_source != ''} {service.name} Logo {:else} {/if} {:else}{/if} {service.name}{server.name} {#if hover.title}
-

{service.desc}

-

{service.warn}

-