Merge media-webui/media-backend into the general shared component/backend system
Extracts a new backend/authproxy package for the AuthGuard-proxy helper
functions (session cookie handling, input normalization, error
translation) that Bitmagnet/GameStream/media-backend/AutoCode/
CollabTable/PubliSafe/SimpleCollection/SyncServer/UnraidMonitor/
OutdoorGames were each independently reimplementing, and repoints all
of them onto it.
Extends packages/web-ui's Button/Badge with the variants media-webui
needed (outline, icon size, primary badge) and promotes EmptyState/
SectionTitle/Metric/StatusWidget/StatusDialog into the shared library,
then migrates media-webui off its own diverged ui/{button,card,badge,
metric} components and local duplicates of the promoted components
onto @gabriel20xx/web-ui, so media-webui is a proper consumer of the
same design system every other project already uses instead of a
parallel fork.
Also removes the dead `desktop`/MediaDesktop service variant from
media-backend and media-webui (MediaDesktop is an Electron client that
never actually runs this stack).
This commit is contained in:
1 parent
9589d07baf
commit
7b5a4e6c2c
49 files changed
+872
-726
No files matched your search
@@ -1,19 +1,21 @@
|
||||
<script lang="ts">
|
||||
import type { HTMLAttributes } from 'svelte/elements';
|
||||
import type { Snippet } from 'svelte';
|
||||
|
||||
type BadgeVariant = 'default' | 'success' | 'warning' | 'danger';
|
||||
type BadgeVariant = 'default' | 'primary' | 'success' | 'warning' | 'danger';
|
||||
|
||||
let {
|
||||
children,
|
||||
class: className = '',
|
||||
variant = 'default'
|
||||
}: {
|
||||
variant = 'default',
|
||||
...rest
|
||||
}: Omit<HTMLAttributes<HTMLSpanElement>, 'class'> & {
|
||||
children?: Snippet;
|
||||
class?: string;
|
||||
variant?: BadgeVariant;
|
||||
} = $props();
|
||||
</script>
|
||||
|
||||
<span class={`sc-badge ${className}`} data-variant={variant}>
|
||||
<span class={`sc-badge ${className}`} data-variant={variant} {...rest}>
|
||||
{@render children?.()}
|
||||
</span>
|
||||
@@ -1,8 +1,9 @@
|
||||
<script lang="ts">
|
||||
import type { HTMLButtonAttributes } from 'svelte/elements';
|
||||
import type { Snippet } from 'svelte';
|
||||
|
||||
type ButtonVariant = 'primary' | 'secondary' | 'ghost' | 'danger';
|
||||
type ButtonSize = 'sm' | 'md' | 'lg';
|
||||
type ButtonVariant = 'primary' | 'secondary' | 'outline' | 'ghost' | 'danger';
|
||||
type ButtonSize = 'sm' | 'md' | 'lg' | 'icon';
|
||||
|
||||
let {
|
||||
children,
|
||||
@@ -12,8 +13,9 @@
|
||||
onclick,
|
||||
size = 'md',
|
||||
type = 'button',
|
||||
variant = 'primary'
|
||||
}: {
|
||||
variant = 'primary',
|
||||
...rest
|
||||
}: Omit<HTMLButtonAttributes, 'class' | 'disabled' | 'onclick' | 'type'> & {
|
||||
children?: Snippet;
|
||||
class?: string;
|
||||
disabled?: boolean;
|
||||
@@ -30,6 +32,7 @@
|
||||
{disabled}
|
||||
{onclick}
|
||||
{type}
|
||||
{...rest}
|
||||
>
|
||||
{@render children?.()}
|
||||
</button>
|
||||
@@ -0,0 +1,13 @@
|
||||
<script lang="ts">
|
||||
import { Inbox } from '@lucide/svelte';
|
||||
|
||||
let { title, message }: { title: string; message: string } = $props();
|
||||
</script>
|
||||
|
||||
<div class="sc-empty-state">
|
||||
<Inbox aria-hidden="true" class="sc-empty-state-icon" size={32} />
|
||||
<div>
|
||||
<p class="sc-empty-state-title">{title}</p>
|
||||
<p class="sc-empty-state-message">{message}</p>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,21 @@
|
||||
<script lang="ts">
|
||||
type MetricVariant = 'default' | 'primary' | 'success' | 'warning' | 'danger';
|
||||
|
||||
let {
|
||||
detail = '',
|
||||
label,
|
||||
value,
|
||||
variant = 'default'
|
||||
}: {
|
||||
detail?: string;
|
||||
label: string;
|
||||
value: string | number;
|
||||
variant?: MetricVariant;
|
||||
} = $props();
|
||||
</script>
|
||||
|
||||
<div class="sc-metric">
|
||||
<p class="sc-metric-label">{label}</p>
|
||||
<p class="sc-metric-value" data-variant={variant}>{value}</p>
|
||||
{#if detail}<p class="sc-metric-detail">{detail}</p>{/if}
|
||||
</div>
|
||||
@@ -0,0 +1,8 @@
|
||||
<script lang="ts">
|
||||
let { title, description = '' }: { title: string; description?: string } = $props();
|
||||
</script>
|
||||
|
||||
<div class="sc-section-title">
|
||||
<h2>{title}</h2>
|
||||
{#if description}<p class="sc-muted">{description}</p>{/if}
|
||||
</div>
|
||||
@@ -0,0 +1,71 @@
|
||||
<script lang="ts">
|
||||
import { AlertCircle, AlertTriangle, CheckCircle2, CircleHelp, LoaderCircle, RefreshCw } from '@lucide/svelte';
|
||||
import Button from './Button.svelte';
|
||||
import Dialog from './Dialog.svelte';
|
||||
import type { StatusProbe, StatusSnapshot } from '../types';
|
||||
|
||||
let {
|
||||
onRefresh,
|
||||
open = $bindable(false),
|
||||
status
|
||||
}: {
|
||||
onRefresh: () => void | Promise<void>;
|
||||
open?: boolean;
|
||||
status: StatusSnapshot;
|
||||
} = $props();
|
||||
|
||||
const levelLabel: Record<StatusSnapshot['level'], string> = {
|
||||
checking: 'Checking',
|
||||
healthy: 'Healthy',
|
||||
degraded: 'Degraded',
|
||||
offline: 'Offline'
|
||||
};
|
||||
|
||||
function probeLabel(probe: StatusProbe | null): string {
|
||||
if (!probe) return 'Not checked';
|
||||
if (probe.ok) return 'OK';
|
||||
if (probe.error) return probe.error;
|
||||
return probe.httpStatus ? `HTTP ${probe.httpStatus}` : 'Unavailable';
|
||||
}
|
||||
</script>
|
||||
|
||||
<Dialog bind:open description="Live liveness and database readiness checks." title="Service status">
|
||||
<div aria-live="polite" class="sc-status-summary" data-level={status.level}>
|
||||
{#if status.loading && status.level === 'checking'}
|
||||
<LoaderCircle aria-hidden="true" class="sc-status-icon sc-status-spin" size={20} />
|
||||
{:else if status.level === 'healthy'}
|
||||
<CheckCircle2 aria-hidden="true" class="sc-status-icon" size={20} />
|
||||
{:else if status.level === 'degraded'}
|
||||
<AlertTriangle aria-hidden="true" class="sc-status-icon" size={20} />
|
||||
{:else if status.level === 'offline'}
|
||||
<AlertCircle aria-hidden="true" class="sc-status-icon" size={20} />
|
||||
{:else}
|
||||
<CircleHelp aria-hidden="true" class="sc-status-icon" size={20} />
|
||||
{/if}
|
||||
<span class="sc-status-summary-label">{levelLabel[status.level]}</span>
|
||||
{#if status.checkedAt}
|
||||
<span class="sc-status-summary-time">{new Date(status.checkedAt).toLocaleTimeString()}</span>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<div class="sc-status-probes">
|
||||
{#each [{ label: 'Liveness', probe: status.health }, { label: 'Readiness / database', probe: status.readiness }] as item (item.label)}
|
||||
<div class="sc-status-probe">
|
||||
<span>{item.label}</span>
|
||||
<span data-ok={item.probe?.ok ?? false}>{probeLabel(item.probe)}</span>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
|
||||
{#if status.health?.service || status.readiness?.service}
|
||||
<p class="sc-muted sc-status-service">Service: {status.health?.service || status.readiness?.service}</p>
|
||||
{/if}
|
||||
|
||||
{#snippet footer()}
|
||||
<Button disabled={status.loading} variant="outline" onclick={() => void onRefresh()}>
|
||||
<RefreshCw aria-hidden="true" class={status.loading ? 'sc-status-spin' : ''} size={16} />
|
||||
Refresh
|
||||
</Button>
|
||||
<Button variant="secondary" onclick={() => (open = false)}>Dismiss</Button>
|
||||
{/snippet}
|
||||
</Dialog>
|
||||
@@ -0,0 +1,103 @@
|
||||
<script lang="ts">
|
||||
import { AlertCircle, AlertTriangle, CheckCircle2, CircleHelp, LoaderCircle } from '@lucide/svelte';
|
||||
import { onMount } from 'svelte';
|
||||
import Button from './Button.svelte';
|
||||
import StatusDialog from './StatusDialog.svelte';
|
||||
import type { StatusProbe, StatusSnapshot } from '../types';
|
||||
|
||||
// Polls this service's own /healthz (liveness) and /ready (readiness,
|
||||
// typically including a database check) endpoints - the convention every
|
||||
// Go/Node/Python backend in this workspace already serves - and shows the
|
||||
// combined result as a small header icon that opens StatusDialog for
|
||||
// detail on click. Both paths are relative, so this widget can drop into
|
||||
// any app without configuration as long as it follows that convention.
|
||||
const initialStatus: StatusSnapshot = {
|
||||
level: 'checking',
|
||||
health: null,
|
||||
readiness: null,
|
||||
checkedAt: null,
|
||||
loading: false
|
||||
};
|
||||
|
||||
let status = $state<StatusSnapshot>(initialStatus);
|
||||
let open = $state(false);
|
||||
let requestInFlight = false;
|
||||
|
||||
async function probe(path: string): Promise<StatusProbe> {
|
||||
try {
|
||||
const response = await fetch(path, {
|
||||
credentials: 'include',
|
||||
headers: { Accept: 'application/json' }
|
||||
});
|
||||
const payload = (await response.json().catch(() => null)) as {
|
||||
ok?: boolean;
|
||||
service?: string;
|
||||
error?: string;
|
||||
} | null;
|
||||
return {
|
||||
path,
|
||||
ok: response.ok && payload?.ok !== false,
|
||||
httpStatus: response.status,
|
||||
service: payload?.service || null,
|
||||
error: response.ok ? null : payload?.error || response.statusText || `HTTP ${response.status}`
|
||||
};
|
||||
} catch (error) {
|
||||
return {
|
||||
path,
|
||||
ok: false,
|
||||
httpStatus: null,
|
||||
service: null,
|
||||
error: error instanceof Error ? error.message : 'Unavailable'
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
async function refresh(): Promise<void> {
|
||||
if (requestInFlight) return;
|
||||
requestInFlight = true;
|
||||
status = { ...status, loading: true, level: status.health || status.readiness ? status.level : 'checking' };
|
||||
|
||||
try {
|
||||
const [health, readiness] = await Promise.all([probe('/healthz'), probe('/ready')]);
|
||||
const level = health.ok && readiness.ok ? 'healthy' : health.ok ? 'degraded' : 'offline';
|
||||
status = {
|
||||
level,
|
||||
health,
|
||||
readiness,
|
||||
checkedAt: new Date().toISOString(),
|
||||
loading: false
|
||||
};
|
||||
} finally {
|
||||
requestInFlight = false;
|
||||
if (status.loading) status = { ...status, loading: false };
|
||||
}
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
void refresh();
|
||||
const timer = window.setInterval(() => void refresh(), 15_000);
|
||||
return () => window.clearInterval(timer);
|
||||
});
|
||||
</script>
|
||||
|
||||
<Button
|
||||
aria-label="Service status"
|
||||
onclick={() => (open = true)}
|
||||
size="icon"
|
||||
title={`Service status: ${status.level}`}
|
||||
variant="ghost"
|
||||
>
|
||||
{#if status.loading && status.level === 'checking'}
|
||||
<LoaderCircle aria-hidden="true" class="sc-status-icon sc-status-spin" size={20} />
|
||||
{:else if status.level === 'healthy'}
|
||||
<CheckCircle2 aria-hidden="true" class="sc-status-icon" size={20} />
|
||||
{:else if status.level === 'degraded'}
|
||||
<AlertTriangle aria-hidden="true" class="sc-status-icon" size={20} />
|
||||
{:else if status.level === 'offline'}
|
||||
<AlertCircle aria-hidden="true" class="sc-status-icon" size={20} />
|
||||
{:else}
|
||||
<CircleHelp aria-hidden="true" class="sc-status-icon" size={20} />
|
||||
{/if}
|
||||
</Button>
|
||||
|
||||
<StatusDialog bind:open {status} onRefresh={refresh} />
|
||||
Reference in new issue
Block a user