aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/routes/(admin)/admin/+page.svelte
diff options
context:
space:
mode:
authorzwlucas <lucas.fariamo08@gmail.com>2026-05-29 21:24:59 +0000
committerzwlucas <lucas.fariamo08@gmail.com>2026-05-29 21:24:59 +0000
commitbf8b1d0d49703e82cf8162399405984bd0b3fe88 (patch)
treeaf4ed5fb7feae49cb3ebe1c8c3f87831e53b8273 /frontend/src/routes/(admin)/admin/+page.svelte
parent17b159c563278c3b3b8b3884be37f8d5025ce0c7 (diff)
downloadyaum-bf8b1d0d49703e82cf8162399405984bd0b3fe88.tar.gz
yaum-bf8b1d0d49703e82cf8162399405984bd0b3fe88.zip
feat: implement static file serving and Docker support, update frontend build process
Signed-off-by: zwlucas <lucas.fariamo08@gmail.com>
Diffstat (limited to 'frontend/src/routes/(admin)/admin/+page.svelte')
-rw-r--r--frontend/src/routes/(admin)/admin/+page.svelte49
1 files changed, 40 insertions, 9 deletions
diff --git a/frontend/src/routes/(admin)/admin/+page.svelte b/frontend/src/routes/(admin)/admin/+page.svelte
index 7fa361d..9a48ba0 100644
--- a/frontend/src/routes/(admin)/admin/+page.svelte
+++ b/frontend/src/routes/(admin)/admin/+page.svelte
@@ -1,5 +1,7 @@
<script lang="ts">
- const API = 'http://localhost:8080/api';
+ import { onMount } from 'svelte';
+
+ const API = '/api';
let { data } = $props();
@@ -8,15 +10,42 @@
let services = $state<any[]>([]);
let showForm = $state(false);
- $effect(() => {
- if (!initialized && data) {
- token = data.token;
- services = data.services ?? [];
- initialized = true;
- fetchMaintenances();
- fetchServerStats();
+ function getCookie(name: string) {
+ return document.cookie.split('; ').find(r => r.startsWith(name + '='))?.split('=')[1] ?? '';
+ }
+
+ async function bootstrap() {
+ if (initialized) return;
+ initialized = true;
+ token = data?.token || getCookie('auth_token') || '';
+ if (data?.services && data.services.length > 0) {
+ services = data.services;
+ } else {
+ await fetchServices();
}
- });
+ fetchMaintenances();
+ fetchServerStats();
+ }
+
+ async function fetchServices() {
+ try {
+ const res = await fetch(`${API}/services`, { headers: { Authorization: `Bearer ${token}` } });
+ if (await handleUnauthorized(res)) return;
+ if (res.ok) {
+ const svcs = await res.json();
+ const withStats = await Promise.all(
+ svcs.map(async (svc: any) => {
+ try {
+ const sr = await fetch(`${API}/services/${svc.id}/stats`, { headers: { Authorization: `Bearer ${token}` } });
+ if (sr.ok) svc.stats = await sr.json();
+ } catch { /* ignore */ }
+ return svc;
+ })
+ );
+ services = withStats;
+ }
+ } catch { /* ignore */ }
+ }
let editingSvc: any = $state(null);
let saving = $state(false);
let formError = $state('');
@@ -24,6 +53,8 @@
let toggling = $state<Record<number, boolean>>({});
// maintenance state
+ onMount(bootstrap);
+
let maintenances = $state<any[]>([]);
let showMtnForm = $state(false);
let editingMtn: any = $state(null);