398 lines
17 KiB
Svelte
398 lines
17 KiB
Svelte
<script lang="ts">
|
|
import { onMount } from 'svelte';
|
|
import Card from '$ui/components/primitives/Card.svelte';
|
|
import Badge from '$ui/components/primitives/Badge.svelte';
|
|
import Button from '$ui/components/primitives/Button.svelte';
|
|
import SectionHeader from '$ui/components/primitives/SectionHeader.svelte';
|
|
import EmptyState from '$ui/components/primitives/EmptyState.svelte';
|
|
import Field from '$ui/components/primitives/Field.svelte';
|
|
import Input from '$ui/components/primitives/Input.svelte';
|
|
import Select from '$ui/components/primitives/Select.svelte';
|
|
import Textarea from '$ui/components/primitives/Textarea.svelte';
|
|
|
|
type ArtifactKind = 'script' | 'config' | 'plugin' | 'baseline';
|
|
interface ArtifactRow {
|
|
id: number; name: string; target_rel_path: string;
|
|
scope_type: 'game' | 'map' | null; scope_value: string | null;
|
|
current_version_id: number | null; kind: ArtifactKind;
|
|
latestVersion: {
|
|
id: number; version: number; sha256: string; size: number;
|
|
state: 'untested' | 'tested' | 'test-failed'; uploaded_at: string;
|
|
} | null;
|
|
versionCount: number;
|
|
servers: string[];
|
|
runningBetaId: number | null;
|
|
}
|
|
interface ScopeOptions { games: string[]; mapsByGame: Record<string, string[]>; }
|
|
|
|
let baselines = $state<ArtifactRow[]>([]);
|
|
let overlays = $state<ArtifactRow[]>([]);
|
|
let loading = $state(true);
|
|
let flash = $state<string | null>(null);
|
|
let uploading = $state(false);
|
|
let scopeOptions = $state<ScopeOptions>({ games: [], mapsByGame: {} });
|
|
let successBanner = $state<{ name: string; artifactId: number; version: number; kind: string } | null>(null);
|
|
|
|
let overlayName = $state('');
|
|
let overlayScopeType = $state<'game' | 'map'>('game');
|
|
let overlayScopeGame = $state('');
|
|
let overlayScopeMap = $state('');
|
|
let overlayText = $state('');
|
|
let overlayNotes = $state('');
|
|
|
|
let baselineName = $state('');
|
|
let baselineScopeGame = $state('');
|
|
let baselineFile = $state<File | null>(null);
|
|
let baselineNotes = $state('');
|
|
|
|
const overlayScopeValue = $derived.by(() => {
|
|
if (overlayScopeType === 'game') return overlayScopeGame;
|
|
return overlayScopeMap;
|
|
});
|
|
|
|
async function load(): Promise<void> {
|
|
try {
|
|
const [baselineRes, overlayRes, scopeRes] = await Promise.all([
|
|
fetch('/api/configs?kind=baseline'),
|
|
fetch('/api/configs?kind=config'),
|
|
fetch('/api/scope-options')
|
|
]);
|
|
if (!baselineRes.ok || !overlayRes.ok) {
|
|
flash = `Configs API returned ${baselineRes.status}/${overlayRes.status}. If dev, restart to run DB migrations.`;
|
|
baselines = []; overlays = [];
|
|
} else {
|
|
baselines = ((await baselineRes.json()) as { scripts?: ArtifactRow[] }).scripts ?? [];
|
|
overlays = ((await overlayRes.json()) as { scripts?: ArtifactRow[] }).scripts ?? [];
|
|
}
|
|
if (scopeRes.ok) {
|
|
scopeOptions = ((await scopeRes.json()) as ScopeOptions | undefined) ?? { games: [], mapsByGame: {} };
|
|
}
|
|
} catch (err) {
|
|
flash = `Failed to load configs: ${(err as Error).message}`;
|
|
} finally {
|
|
loading = false;
|
|
}
|
|
}
|
|
onMount(load);
|
|
|
|
async function createOverlay(e: Event): Promise<void> {
|
|
e.preventDefault();
|
|
if (uploading) return;
|
|
if (!overlayName.trim()) { flash = 'Name is required'; return; }
|
|
if (!overlayScopeValue) { flash = `Pick a ${overlayScopeType}`; return; }
|
|
if (!/^\s*set\s+\S+\s+/m.test(overlayText)) {
|
|
flash = 'Overlay must contain at least one `set KEY VALUE` line';
|
|
return;
|
|
}
|
|
uploading = true; flash = null;
|
|
const form = new FormData();
|
|
form.append('name', overlayName.trim());
|
|
form.append('kind', 'config');
|
|
form.append('scopeType', overlayScopeType);
|
|
form.append('scopeValue', overlayScopeValue);
|
|
form.append('text', overlayText);
|
|
if (overlayNotes.trim()) form.append('notes', overlayNotes.trim());
|
|
try {
|
|
const res = await fetch('/api/configs', { method: 'POST', body: form });
|
|
const body = (await res.json()) as { ok: boolean; error?: string; script?: { id: number; name: string } };
|
|
if (!res.ok || !body.ok) { flash = body.error ?? `HTTP ${res.status}`; return; }
|
|
successBanner = body.script
|
|
? { name: body.script.name, artifactId: body.script.id, version: 1, kind: 'config overlay' }
|
|
: null;
|
|
overlayName = ''; overlayText = ''; overlayNotes = '';
|
|
await load();
|
|
} finally {
|
|
uploading = false;
|
|
}
|
|
}
|
|
|
|
function pickBaselineFile(e: Event): void {
|
|
const t = e.target as HTMLInputElement;
|
|
baselineFile = t.files?.[0] ?? null;
|
|
if (!baselineName && baselineFile) baselineName = baselineFile.name.replace(/\.[^.]+$/, '');
|
|
}
|
|
|
|
async function createBaseline(e: Event): Promise<void> {
|
|
e.preventDefault();
|
|
if (uploading) return;
|
|
if (!baselineName.trim() || !baselineFile || !baselineScopeGame) {
|
|
flash = 'Name, game, and cfg file are required';
|
|
return;
|
|
}
|
|
uploading = true; flash = null;
|
|
const form = new FormData();
|
|
form.append('name', baselineName.trim());
|
|
form.append('kind', 'baseline');
|
|
form.append('scopeType', 'game');
|
|
form.append('scopeValue', baselineScopeGame);
|
|
form.append('content', baselineFile);
|
|
if (baselineNotes.trim()) form.append('notes', baselineNotes.trim());
|
|
try {
|
|
const res = await fetch('/api/configs', { method: 'POST', body: form });
|
|
const body = (await res.json()) as { ok: boolean; error?: string; script?: { id: number; name: string } };
|
|
if (!res.ok || !body.ok) { flash = body.error ?? `HTTP ${res.status}`; return; }
|
|
successBanner = body.script
|
|
? { name: body.script.name, artifactId: body.script.id, version: 1, kind: 'baseline' }
|
|
: null;
|
|
baselineName = ''; baselineScopeGame = ''; baselineFile = null; baselineNotes = '';
|
|
await load();
|
|
} finally {
|
|
uploading = false;
|
|
}
|
|
}
|
|
|
|
function scopeLabel(a: ArtifactRow): string {
|
|
if (!a.scope_type) return 'unscoped';
|
|
return `${a.scope_type} · ${a.scope_value ?? '?'}`;
|
|
}
|
|
function stateVariantFor(a: ArtifactRow): 'online' | 'warning' | 'danger' | 'neutral' | null {
|
|
if (!a.latestVersion) return null;
|
|
if (a.current_version_id === null) return 'neutral';
|
|
if (a.latestVersion.id !== a.current_version_id) {
|
|
if (a.latestVersion.state === 'untested') return 'neutral';
|
|
if (a.latestVersion.state === 'tested') return 'online';
|
|
if (a.latestVersion.state === 'test-failed') return 'danger';
|
|
}
|
|
return null;
|
|
}
|
|
function stateLabel(a: ArtifactRow): string {
|
|
if (!a.latestVersion) return '';
|
|
if (a.current_version_id === null) return 'untested';
|
|
if (a.latestVersion.id !== a.current_version_id) {
|
|
return `v${a.latestVersion.version} ${a.latestVersion.state.replace('-', ' ')}`;
|
|
}
|
|
return '';
|
|
}
|
|
|
|
let gameOptions = $derived([
|
|
{ value: '', label: '— Pick a game —', disabled: true },
|
|
...scopeOptions.games.map((g) => ({ value: g, label: g }))
|
|
]);
|
|
let mapOptions = $derived([
|
|
{ value: '', label: '— Pick a map —', disabled: true },
|
|
...(scopeOptions.mapsByGame[overlayScopeGame] ?? []).map((m) => ({ value: m, label: m }))
|
|
]);
|
|
let scopeTypeOptions = [
|
|
{ value: 'game', label: 'Game' },
|
|
{ value: 'map', label: 'Map' }
|
|
];
|
|
</script>
|
|
|
|
<div class="page">
|
|
<SectionHeader
|
|
title="Configs"
|
|
subtitle="One baseline per game, plus scoped overlays. Each server's selected map is applied automatically."
|
|
/>
|
|
|
|
{#if successBanner}
|
|
<div class="banner">
|
|
<strong>v{successBanner.version} of "{successBanner.name}" ({successBanner.kind}) uploaded — untested.</strong>
|
|
<span>Open a beta on <a href="/betas">the betas page</a> to test it before promotion.</span>
|
|
</div>
|
|
{/if}
|
|
|
|
<!-- Baseline upload -->
|
|
<Card padding="lg">
|
|
<h2 class="panel-title">Upload a baseline <span class="dim">(one per game)</span></h2>
|
|
<form onsubmit={createBaseline} class="upload-form">
|
|
<Field label="Name">
|
|
<Input bind:value={baselineName} placeholder="t5 baseline" disabled={uploading} />
|
|
</Field>
|
|
<Field label="Game">
|
|
<Select bind:value={baselineScopeGame} options={gameOptions} disabled={uploading} />
|
|
</Field>
|
|
<Field label="Notes" hint="Optional. Describe what this baseline covers.">
|
|
<Input bind:value={baselineNotes} placeholder="dedicated_sp.cfg baseline" disabled={uploading} />
|
|
</Field>
|
|
<Field label="Cfg file (dedicated_sp.cfg)">
|
|
<Input type="file" accept=".cfg,text/plain" onchange={pickBaselineFile} disabled={uploading} />
|
|
</Field>
|
|
<div class="form-actions">
|
|
<Button
|
|
type="submit"
|
|
variant="primary"
|
|
disabled={uploading || !baselineFile || !baselineName || !baselineScopeGame}
|
|
loading={uploading}
|
|
>
|
|
Upload baseline
|
|
</Button>
|
|
</div>
|
|
</form>
|
|
</Card>
|
|
|
|
<!-- Overlay creation -->
|
|
<Card padding="lg">
|
|
<h2 class="panel-title">Create a config overlay</h2>
|
|
<form onsubmit={createOverlay} class="upload-form">
|
|
<Field label="Name">
|
|
<Input bind:value={overlayName} placeholder="disable AFK" disabled={uploading} />
|
|
</Field>
|
|
<Field label="Scope">
|
|
<div class="scope-row">
|
|
<Select bind:value={overlayScopeType} options={scopeTypeOptions} disabled={uploading} />
|
|
<Select bind:value={overlayScopeGame} options={gameOptions} disabled={uploading} />
|
|
{#if overlayScopeType === 'map'}
|
|
<Select bind:value={overlayScopeMap} options={mapOptions} disabled={uploading || !overlayScopeGame} />
|
|
{/if}
|
|
</div>
|
|
</Field>
|
|
<div class="full">
|
|
<Field label="Overlay lines" hint="One or more `set KEY "VALUE"` lines. The server's selected map takes precedence over sv_maprotation; no map-choice overlay is needed.">
|
|
<Textarea
|
|
bind:value={overlayText}
|
|
rows={4}
|
|
mono
|
|
placeholder={'set g_inactivity "0"'}
|
|
disabled={uploading}
|
|
/>
|
|
</Field>
|
|
</div>
|
|
<Field label="Notes" hint="Optional. Explain the reason for this overlay.">
|
|
<Input bind:value={overlayNotes} placeholder="why this change" disabled={uploading} />
|
|
</Field>
|
|
<div class="form-actions">
|
|
<Button
|
|
type="submit"
|
|
variant="primary"
|
|
disabled={uploading || !overlayName || !overlayText || !overlayScopeValue}
|
|
loading={uploading}
|
|
>
|
|
Create overlay
|
|
</Button>
|
|
{#if flash}<span class="flash">{flash}</span>{/if}
|
|
</div>
|
|
</form>
|
|
</Card>
|
|
|
|
<!-- Baselines list -->
|
|
<section class="section">
|
|
<div class="section-head">
|
|
<h2>Baselines</h2>
|
|
<Badge variant="neutral" size="sm">{baselines.length}</Badge>
|
|
</div>
|
|
{#if loading}
|
|
<div class="loading">Loading…</div>
|
|
{:else if baselines.length === 0}
|
|
<EmptyState title="No baseline yet" description="Upload a per-game baseline above." />
|
|
{:else}
|
|
<div class="rows">
|
|
{#each baselines as a (a.id)}
|
|
{@render artifactRow(a)}
|
|
{/each}
|
|
</div>
|
|
{/if}
|
|
</section>
|
|
|
|
<!-- Overlays list -->
|
|
<section class="section">
|
|
<div class="section-head">
|
|
<h2>Overlays</h2>
|
|
<Badge variant="neutral" size="sm">{overlays.length}</Badge>
|
|
</div>
|
|
{#if loading}
|
|
<div class="loading">Loading…</div>
|
|
{:else if overlays.length === 0}
|
|
<EmptyState title="No overlays yet" description="Create a scoped overlay above." />
|
|
{:else}
|
|
<div class="rows">
|
|
{#each overlays as a (a.id)}
|
|
{@render artifactRow(a)}
|
|
{/each}
|
|
</div>
|
|
{/if}
|
|
</section>
|
|
</div>
|
|
|
|
{#snippet artifactRow(a: ArtifactRow)}
|
|
<a class="row" href="/configs/{a.id}">
|
|
<div class="row-top">
|
|
<span class="name">{a.name}</span>
|
|
<Badge
|
|
variant={a.scope_type === 'game' ? 'info' : a.scope_type === 'map' ? 'warning' : 'neutral'}
|
|
size="sm"
|
|
>
|
|
{scopeLabel(a)}
|
|
</Badge>
|
|
{#if stateVariantFor(a)}
|
|
{@const v = stateVariantFor(a)!}
|
|
<Badge variant={v} size="sm">{stateLabel(a)}</Badge>
|
|
{/if}
|
|
{#if a.runningBetaId}
|
|
<Badge variant="warning" size="sm">β{a.runningBetaId} running</Badge>
|
|
{/if}
|
|
</div>
|
|
<div class="row-meta">
|
|
<span class="path">{a.target_rel_path}</span>
|
|
<span>v{a.latestVersion?.version ?? '—'} · {a.versionCount} version{a.versionCount === 1 ? '' : 's'}</span>
|
|
{#if a.servers.length}
|
|
<span>{a.servers.length} matching server{a.servers.length === 1 ? '' : 's'}</span>
|
|
{/if}
|
|
</div>
|
|
</a>
|
|
{/snippet}
|
|
|
|
<style>
|
|
.page { display: flex; flex-direction: column; gap: var(--space-6); }
|
|
.loading { text-align: center; padding: var(--space-12); color: var(--text-tertiary); }
|
|
|
|
.banner {
|
|
display: flex; flex-direction: column; gap: 4px;
|
|
padding: var(--space-3) var(--space-4);
|
|
background: rgba(124, 212, 255, 0.06);
|
|
border: 1px solid rgba(124, 212, 255, 0.22);
|
|
border-radius: var(--radius-md);
|
|
font-size: var(--text-sm);
|
|
}
|
|
.banner a { color: var(--state-online); text-decoration: underline; }
|
|
|
|
.panel-title {
|
|
margin: 0 0 var(--space-4);
|
|
font-family: var(--font-body);
|
|
font-size: var(--text-md);
|
|
font-weight: var(--weight-semibold);
|
|
color: var(--text-primary);
|
|
}
|
|
.panel-title .dim {
|
|
color: var(--text-tertiary);
|
|
font-weight: var(--weight-regular);
|
|
font-size: var(--text-sm);
|
|
}
|
|
|
|
.upload-form { display: grid; gap: var(--space-4); grid-template-columns: 1fr 1fr; }
|
|
.upload-form .full { grid-column: 1 / -1; }
|
|
.scope-row { display: flex; gap: var(--space-2); flex-wrap: wrap; }
|
|
.scope-row :global(.wrap) { flex: 1 1 140px; min-width: 140px; }
|
|
.form-actions { grid-column: 1 / -1; display: flex; align-items: center; gap: var(--space-4); }
|
|
.flash { color: var(--state-danger); font-family: var(--font-mono); font-size: var(--text-xs); }
|
|
|
|
.section { display: flex; flex-direction: column; gap: var(--space-3); }
|
|
.section-head { display: flex; align-items: center; gap: var(--space-3); }
|
|
.section-head h2 {
|
|
margin: 0;
|
|
font-family: var(--font-body);
|
|
font-size: var(--text-md);
|
|
font-weight: var(--weight-semibold);
|
|
color: var(--text-primary);
|
|
}
|
|
|
|
.rows { display: flex; flex-direction: column; gap: var(--space-2); }
|
|
.row {
|
|
display: flex; flex-direction: column; gap: var(--space-2);
|
|
padding: var(--space-4) var(--space-5);
|
|
background: color-mix(in oklab, var(--surface) 88%, transparent);
|
|
border: 1px solid var(--border-subtle);
|
|
border-radius: var(--radius-md);
|
|
color: var(--text-primary);
|
|
text-decoration: none;
|
|
transition: background-color var(--dur-fast) var(--ease-standard), border-color var(--dur-fast) var(--ease-standard);
|
|
}
|
|
.row:hover { background: var(--surface-raised); border-color: var(--border-strong); }
|
|
.row:focus-visible { outline: none; box-shadow: var(--focus-ring); }
|
|
.row-top { display: flex; gap: var(--space-2); align-items: center; flex-wrap: wrap; }
|
|
.name { font-size: var(--text-md); font-weight: var(--weight-semibold); color: var(--text-primary); letter-spacing: var(--tracking-tight); }
|
|
.row-meta { display: flex; gap: var(--space-5); color: var(--text-tertiary); font-family: var(--font-mono); font-size: var(--text-xs); flex-wrap: wrap; }
|
|
.path { color: var(--text-secondary); }
|
|
|
|
@media (max-width: 720px) { .upload-form { grid-template-columns: 1fr; } }
|
|
</style>
|