config and plugin

This commit is contained in:
2026-09-12 19:11:44 -04:00
parent 85bcb05a7d
commit 8c40bbeff1
19 changed files with 1685 additions and 86 deletions
+2
View File
@@ -25,6 +25,8 @@
<div class="tabs">
<a href="/" class:on={$page.url.pathname === '/'}>Fleet</a>
<a href="/scripts" class:on={$page.url.pathname.startsWith('/scripts')}>Scripts</a>
<a href="/configs" class:on={$page.url.pathname.startsWith('/configs')}>Configs</a>
<a href="/plugins" class:on={$page.url.pathname.startsWith('/plugins')}>Plugins</a>
<a href="/deployments" class:on={$page.url.pathname.startsWith('/deployments')}>Deployments</a>
<a href="/betas" class:on={$page.url.pathname.startsWith('/betas')}>Betas</a>
</div>
+18 -5
View File
@@ -24,6 +24,7 @@ export async function GET({ url }: { url: URL }) {
id: bs.script_id,
name: script?.name ?? '(deleted)',
target_rel_path: script?.target_rel_path ?? '',
kind: script?.kind ?? bs.kind ?? 'script',
version: version
? { id: version.id, version: version.version, sha256: version.sha256 }
: null
@@ -38,9 +39,13 @@ export async function GET({ url }: { url: URL }) {
return json({ betas: rows });
}
// POST body: { scripts: [{ scriptId, scriptVersionId }], servers[], waitForHealth, waitForMatch, notes? }
// POST body accepts either:
// { artifacts: [{ id, versionId }], ... } — polymorphic (script/config/plugin/baseline)
// or the legacy form:
// { scripts: [{ scriptId, scriptVersionId }], ... }
export async function POST({ request }: { request: Request }) {
const body = (await request.json().catch(() => ({}))) as {
artifacts?: Array<{ id?: number; versionId?: number }>;
scripts?: Array<{ scriptId?: number; scriptVersionId?: number }>;
servers?: string[];
waitForHealth?: boolean;
@@ -48,9 +53,17 @@ export async function POST({ request }: { request: Request }) {
notes?: string;
};
if (!Array.isArray(body.scripts) || body.scripts.length === 0 || !Array.isArray(body.servers)) {
// Normalize into the openBeta shape. Both fields feed the same list.
const rawEntries: Array<{ scriptId?: number; scriptVersionId?: number }> = [];
if (Array.isArray(body.artifacts)) {
for (const a of body.artifacts) rawEntries.push({ scriptId: a.id, scriptVersionId: a.versionId });
}
if (Array.isArray(body.scripts)) {
for (const s of body.scripts) rawEntries.push({ scriptId: s.scriptId, scriptVersionId: s.scriptVersionId });
}
if (rawEntries.length === 0 || !Array.isArray(body.servers)) {
return json(
{ ok: false, error: 'scripts[] (non-empty) and servers[] are required' },
{ ok: false, error: 'artifacts[]/scripts[] (non-empty) and servers[] are required' },
{ status: 400 }
);
}
@@ -58,10 +71,10 @@ export async function POST({ request }: { request: Request }) {
return json({ ok: false, error: 'at least one server is required' }, { status: 400 });
}
const normalized: Array<{ scriptId: number; scriptVersionId: number }> = [];
for (const s of body.scripts) {
for (const s of rawEntries) {
if (typeof s.scriptId !== 'number' || typeof s.scriptVersionId !== 'number') {
return json(
{ ok: false, error: 'each scripts[] entry needs scriptId and scriptVersionId' },
{ ok: false, error: 'each entry needs scriptId/id and scriptVersionId/versionId' },
{ status: 400 }
);
}
+1
View File
@@ -20,6 +20,7 @@ export async function GET({ params }: { params: { id: string } }) {
id: bs.script_id,
name: script?.name ?? '(deleted)',
target_rel_path: script?.target_rel_path ?? '',
kind: script?.kind ?? bs.kind ?? 'script',
version: version
? { id: version.id, version: version.version, sha256: version.sha256 }
: null
+25
View File
@@ -0,0 +1,25 @@
// Thin wrapper around /api/scripts pinned to config-kind artifacts. Both
// overlays (kind='config') and baselines (kind='baseline') share this endpoint
// — the caller sets `kind` in the form (defaults to 'config').
import { GET as scriptsGET, POST as scriptsPOST } from '../scripts/+server.js';
function withDefaultKind(url: URL, fallback: string): URL {
if (!url.searchParams.has('kind')) {
const clone = new URL(url.href);
clone.searchParams.set('kind', fallback);
return clone;
}
return url;
}
export async function GET(event: { url: URL }) {
// Default to listing overlays. Baselines live at /api/configs?kind=baseline.
return scriptsGET({ url: withDefaultKind(event.url, 'config') });
}
export async function POST(event: { request: Request; url: URL }) {
return scriptsPOST({
request: event.request,
url: withDefaultKind(event.url, 'config')
});
}
+22
View File
@@ -0,0 +1,22 @@
// Thin wrapper around /api/scripts pinned to plugin-kind artifacts.
import { GET as scriptsGET, POST as scriptsPOST } from '../scripts/+server.js';
function withDefaultKind(url: URL, fallback: string): URL {
if (!url.searchParams.has('kind')) {
const clone = new URL(url.href);
clone.searchParams.set('kind', fallback);
return clone;
}
return url;
}
export async function GET(event: { url: URL }) {
return scriptsGET({ url: withDefaultKind(event.url, 'plugin') });
}
export async function POST(event: { request: Request; url: URL }) {
return scriptsPOST({
request: event.request,
url: withDefaultKind(event.url, 'plugin')
});
}
+43 -13
View File
@@ -1,10 +1,12 @@
import { json } from '@sveltejs/kit';
import {
createScript,
isArtifactKind,
listScripts,
listVersions,
serversMatchingScope,
ScriptError,
type ArtifactKind,
type ScopeType
} from '$lib/server/fleet/scripts.js';
import { findRunningBetaForScript } from '$lib/server/fleet/beta.js';
@@ -17,8 +19,18 @@ function scopeTypeOrNull(v: FormDataEntryValue | null): ScopeType | null {
throw new ScriptError(`invalid scope_type: ${s}`, 'invalid-scope');
}
export async function GET() {
const scripts = listScripts().map((s) => {
function kindOrDefault(v: FormDataEntryValue | string | null, fallback: ArtifactKind = 'script'): ArtifactKind {
if (v === null || v === undefined || v === '') return fallback;
const s = String(v);
if (!isArtifactKind(s)) throw new ScriptError(`invalid kind: ${s}`, 'invalid-kind');
return s;
}
export async function GET({ url }: { url: URL }) {
const kindParam = url.searchParams.get('kind');
const kindFilter = kindParam ? (isArtifactKind(kindParam) ? kindParam : null) : null;
const rows = kindFilter ? listScripts(kindFilter) : listScripts();
const scripts = rows.map((s) => {
const versions = listVersions(s.id);
const matched = s.scope_type && s.scope_value
? serversMatchingScope(s.scope_type as ScopeType, s.scope_value)
@@ -44,28 +56,45 @@ export async function GET() {
return json({ scripts });
}
// Multipart POST — creates a script + version 1 from a single file upload.
// Fields: name (text), scopeType (optional: 'game'|'map'), scopeValue
// (optional string), notes (optional), content (file). The target rel path
// defaults to the uploaded filename — T5 servers keep all scripts in a flat
// sp/ directory, so there's no sub-path to specify.
export async function POST({ request }: { request: Request }) {
// Multipart POST — creates an artifact + version 1 from either an uploaded
// file (script/plugin/baseline) or a text body (config overlay). Fields:
// name, scopeType, scopeValue, notes, kind (defaults to 'script'),
// content (file). Configs may alternatively send `text` as a form field.
export async function POST({ request, url }: { request: Request; url: URL }) {
const form = await request.formData();
const name = String(form.get('name') ?? '').trim();
const notes = form.get('notes') ? String(form.get('notes')) : undefined;
let scopeType: ScopeType | null;
let kind: ArtifactKind;
try {
scopeType = scopeTypeOrNull(form.get('scopeType'));
// Kind may come from the form or the query string (thin wrappers use ?kind=).
const kindRaw = form.get('kind') ?? url.searchParams.get('kind');
kind = kindOrDefault(kindRaw);
} catch (err) {
return json({ ok: false, error: (err as Error).message }, { status: 400 });
}
const scopeValueRaw = form.get('scopeValue');
const scopeValue = scopeValueRaw ? String(scopeValueRaw).trim() : null;
const file = form.get('content');
if (!(file instanceof File)) return json({ ok: false, error: 'content file is required' }, { status: 400 });
const targetRelPath = file.name;
const content = Buffer.from(await file.arrayBuffer());
let content: Buffer;
let uploadedFilename: string | null = null;
const file = form.get('content');
const text = form.get('text');
if (file instanceof File && file.size > 0) {
content = Buffer.from(await file.arrayBuffer());
uploadedFilename = file.name;
} else if (typeof text === 'string' && text.length > 0) {
content = Buffer.from(text, 'utf8');
} else {
return json({ ok: false, error: 'content file or text is required' }, { status: 400 });
}
// Target rel path: for script/plugin, default to the upload filename.
// For config/baseline, createScript() defaults to config.configTargetFile.
const targetRelPath = kind === 'script' || kind === 'plugin'
? uploadedFilename ?? undefined
: undefined;
try {
const { script, version } = createScript({
@@ -74,7 +103,8 @@ export async function POST({ request }: { request: Request }) {
scopeType,
scopeValue,
content,
notes
notes,
kind
});
return json({ ok: true, script, versionId: version.id });
} catch (err) {
+12 -7
View File
@@ -2,6 +2,7 @@
import { onMount } from 'svelte';
import { goto } from '$app/navigation';
type ArtifactKind = 'script' | 'config' | 'plugin' | 'baseline';
interface BetaListRow {
id: number;
state: 'running' | 'ready-promote' | 'promoted' | 'rolled-back';
@@ -13,6 +14,7 @@
id: number;
name: string;
target_rel_path: string;
kind: ArtifactKind;
version: { id: number; version: number; sha256: string } | null;
}>;
servers: Array<{ server: string; stage: string; error: string | null }>;
@@ -25,6 +27,7 @@
scope_type: 'game' | 'map' | null;
scope_value: string | null;
current_version_id: number | null;
kind: ArtifactKind;
latestVersion: {
id: number;
version: number;
@@ -229,12 +232,14 @@
);
function summarizeScripts(b: BetaListRow): string {
if (b.scripts.length === 0) return '(no scripts)';
if (b.scripts.length === 0) return '(no artifacts)';
if (b.scripts.length === 1) {
const s = b.scripts[0];
return `${s.name} · v${s.version?.version ?? '?'}`;
return `[${s.kind}] ${s.name} · v${s.version?.version ?? '?'}`;
}
return `${b.scripts.length} scripts`;
const byKind: Record<string, number> = {};
for (const s of b.scripts) byKind[s.kind] = (byKind[s.kind] ?? 0) + 1;
return Object.entries(byKind).map(([k, n]) => `${n} ${k}${n === 1 ? '' : 's'}`).join(', ');
}
</script>
@@ -246,7 +251,7 @@
<section class="panel">
<h2>Open a beta</h2>
{#if eligibleScripts.length === 0}
<p class="empty">no scripts with untested versions — upload a new version from a script's page</p>
<p class="empty">no artifacts with untested versions — upload a new version from a scripts / configs / plugins page</p>
{:else}
<form onsubmit={openNewBeta} class="new-beta-form">
<div class="picks">
@@ -256,9 +261,9 @@
bind:value={row.scriptId}
onchange={() => onPickScript(idx)}
>
<option value={null}>— pick a script —</option>
<option value={null}>— pick an artifact —</option>
{#each eligibleForRow(idx) as s (s.id)}
<option value={s.id}>{s.name}</option>
<option value={s.id}>[{s.kind}] {s.name}</option>
{/each}
</select>
<select bind:value={row.versionId} disabled={row.scriptId === null}>
@@ -280,7 +285,7 @@
</div>
{/each}
</div>
<button type="button" class="add-row" onclick={addRow}>+ add script</button>
<button type="button" class="add-row" onclick={addRow}>+ add artifact</button>
<label>
<span class="k">test servers</span>
+4 -2
View File
@@ -32,6 +32,7 @@
id: number;
name: string;
target_rel_path: string;
kind: 'script' | 'config' | 'plugin' | 'baseline';
version: { id: number; version: number; sha256: string } | null;
}
@@ -118,13 +119,14 @@
</div>
<section class="panel">
<h2>Scripts · {scripts.length}</h2>
<h2>Artifacts · {scripts.length}</h2>
{#if scripts.length === 0}
<p class="empty">no scripts bundled in this beta</p>
<p class="empty">no artifacts bundled in this beta</p>
{:else}
<div class="script-list">
{#each scripts as s (s.id)}
<div class="script-row">
<span class="s-kind mono">[{s.kind}]</span>
<a class="s-name" href="/scripts/{s.id}">{s.name}</a>
<span class="s-target mono">{s.target_rel_path}</span>
<span class="s-ver mono">v{s.version?.version ?? '?'}</span>
+373
View File
@@ -0,0 +1,373 @@
<script lang="ts">
import { onMount } from '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[]>;
}
// Two lists: baselines (kind='baseline') and overlays (kind='config').
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);
// Overlay form state
let overlayName = $state('');
let overlayScopeType = $state<'game' | 'map'>('game');
let overlayScopeGame = $state('');
let overlayScopeMap = $state('');
let overlayText = $state('');
let overlayNotes = $state('');
// Baseline form 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> {
const [baselineRes, overlayRes, scopeRes] = await Promise.all([
fetch('/api/configs?kind=baseline'),
fetch('/api/configs?kind=config'),
fetch('/api/scope-options')
]);
baselines = (await baselineRes.json()).scripts;
overlays = (await overlayRes.json()).scripts;
scopeOptions = (await scopeRes.json()) as ScopeOptions;
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 stateTag(a: ArtifactRow): { label: string; cls: string } | null {
if (!a.latestVersion) return null;
if (a.current_version_id === null) return { label: 'untested', cls: 'state-untested' };
if (a.latestVersion.id !== a.current_version_id) {
return { label: `v${a.latestVersion.version} ${a.latestVersion.state}`, cls: `state-${a.latestVersion.state}` };
}
return null;
}
</script>
<h1>Configs</h1>
<section class="panel">
<h2>Upload a baseline (one per game)</h2>
{#if successBanner}
<div class="banner banner-info">
<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 it can be promoted.</span>
</div>
{/if}
<form onsubmit={createBaseline} class="upload-form">
<label>
<span class="k">name</span>
<input type="text" bind:value={baselineName} placeholder="t5 baseline" disabled={uploading} />
</label>
<label>
<span class="k">game</span>
<select bind:value={baselineScopeGame} disabled={uploading}>
<option value="">— pick a game —</option>
{#each scopeOptions.games as g (g)}
<option value={g}>{g}</option>
{/each}
</select>
</label>
<label>
<span class="k">notes (optional)</span>
<input type="text" bind:value={baselineNotes} placeholder="dedicated_sp.cfg baseline" disabled={uploading} />
</label>
<label>
<span class="k">cfg file (dedicated_sp.cfg)</span>
<input type="file" accept=".cfg,text/plain" onchange={pickBaselineFile} disabled={uploading} />
</label>
<button type="submit" class="primary" disabled={uploading || !baselineFile || !baselineName || !baselineScopeGame}>
{uploading ? 'uploading…' : 'upload baseline'}
</button>
</form>
</section>
<section class="panel">
<h2>Create a config overlay</h2>
<form onsubmit={createOverlay} class="upload-form">
<label>
<span class="k">name</span>
<input type="text" bind:value={overlayName} placeholder="disable AFK" disabled={uploading} />
</label>
<label>
<span class="k">scope</span>
<div class="scope-row">
<select bind:value={overlayScopeType} disabled={uploading}>
<option value="game">game</option>
<option value="map">map</option>
</select>
{#if overlayScopeType === 'game'}
<select bind:value={overlayScopeGame} disabled={uploading}>
<option value="">— pick a game —</option>
{#each scopeOptions.games as g (g)}
<option value={g}>{g}</option>
{/each}
</select>
{:else}
<select bind:value={overlayScopeGame} disabled={uploading}>
<option value="">— pick a game —</option>
{#each scopeOptions.games as g (g)}
<option value={g}>{g}</option>
{/each}
</select>
<select bind:value={overlayScopeMap} disabled={uploading || !overlayScopeGame}>
<option value="">— pick a map —</option>
{#each (scopeOptions.mapsByGame[overlayScopeGame] ?? []) as m (m)}
<option value={m}>{m}</option>
{/each}
</select>
{/if}
</div>
</label>
<label class="full">
<span class="k">overlay lines</span>
<textarea
bind:value={overlayText}
rows="4"
placeholder={'set g_inactivity "0"'}
disabled={uploading}
></textarea>
<span class="hint">one or more `set KEY "VALUE"` lines. Replaces baseline lines with the same KEY.</span>
</label>
<label>
<span class="k">notes (optional)</span>
<input type="text" bind:value={overlayNotes} placeholder="why this change" disabled={uploading} />
</label>
<button type="submit" class="primary" disabled={uploading || !overlayName || !overlayText || !overlayScopeValue}>
{uploading ? 'uploading…' : 'create overlay'}
</button>
</form>
{#if flash}<p class="flash">{flash}</p>{/if}
</section>
<section class="panel">
<h2>Baselines · {baselines.length}</h2>
{#if loading}
<p class="empty">loading…</p>
{:else if baselines.length === 0}
<p class="empty">no baseline yet — upload one above</p>
{:else}
<div class="artifacts">
{#each baselines as a (a.id)}
<a class="artifact-row" href="/scripts/{a.id}">
<div class="row-top">
<span class="artifact-name">{a.name}</span>
<span class="scope tag scope-{a.scope_type ?? 'none'}">{scopeLabel(a)}</span>
{#if stateTag(a)}
{@const t = stateTag(a)!}
<span class="tag {t.cls}">{t.label}</span>
{/if}
{#if a.runningBetaId}
<span class="tag beta">beta {a.runningBetaId} running</span>
{/if}
</div>
<div class="row-meta mono">
<span>{a.target_rel_path}</span>
<span>v{a.latestVersion?.version ?? '—'} · {a.versionCount} version{a.versionCount === 1 ? '' : 's'}</span>
<span>{a.servers.length ? `${a.servers.length} matching server${a.servers.length === 1 ? '' : 's'}` : ''}</span>
</div>
</a>
{/each}
</div>
{/if}
</section>
<section class="panel">
<h2>Overlays · {overlays.length}</h2>
{#if loading}
<p class="empty">loading…</p>
{:else if overlays.length === 0}
<p class="empty">no overlays yet — create one above</p>
{:else}
<div class="artifacts">
{#each overlays as a (a.id)}
<a class="artifact-row" href="/scripts/{a.id}">
<div class="row-top">
<span class="artifact-name">{a.name}</span>
<span class="scope tag scope-{a.scope_type ?? 'none'}">{scopeLabel(a)}</span>
{#if stateTag(a)}
{@const t = stateTag(a)!}
<span class="tag {t.cls}">{t.label}</span>
{/if}
{#if a.runningBetaId}
<span class="tag beta">beta {a.runningBetaId} running</span>
{/if}
</div>
<div class="row-meta mono">
<span>v{a.latestVersion?.version ?? '—'} · {a.versionCount} version{a.versionCount === 1 ? '' : 's'}</span>
<span>{a.servers.length ? `${a.servers.length} matching server${a.servers.length === 1 ? '' : 's'}` : ''}</span>
</div>
</a>
{/each}
</div>
{/if}
</section>
<style>
h1 { color: var(--cream); font-family: var(--font-display); font-size: var(--text-3xl); letter-spacing: var(--tracking-display); line-height: var(--leading-tight); margin: 0 0 28px; }
.panel { background: var(--bg-nav); border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--pad-panel); margin-bottom: 20px; }
h2 { margin: 0 0 14px; font-family: var(--font-body); font-size: var(--text-xs); font-weight: 700; text-transform: uppercase; letter-spacing: 1.5px; color: var(--ink-300); }
.empty { color: var(--ink-500); font-family: var(--font-mono); font-size: var(--text-mono); margin: 0; }
.upload-form { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; }
.upload-form label { display: flex; flex-direction: column; gap: 6px; font-size: var(--text-xs); }
.upload-form label.full { grid-column: 1 / -1; }
.upload-form label .k { color: var(--ink-500); text-transform: uppercase; letter-spacing: 1px; }
.upload-form .hint { color: var(--ink-500); font-family: var(--font-mono); font-size: var(--text-mono-sm); }
.upload-form input[type=text], .upload-form select, .upload-form input[type=file], .upload-form textarea {
background: var(--bg-page);
color: var(--ink-100);
border: 1px solid var(--border);
border-radius: var(--r-sm);
padding: 10px 12px;
font-family: var(--font-mono);
font-size: var(--text-mono);
}
.upload-form textarea { min-height: 100px; resize: vertical; }
.upload-form input[type=text]:focus, .upload-form select:focus, .upload-form textarea:focus {
outline: none; border-color: var(--accent); box-shadow: var(--accent-glow);
}
.scope-row { display: flex; gap: 8px; flex-wrap: wrap; }
.scope-row select:nth-of-type(1) { flex: 0 0 120px; }
.scope-row select:nth-of-type(2), .scope-row select:nth-of-type(3) { flex: 1; }
.primary {
grid-column: 1 / -1;
background: linear-gradient(180deg, var(--blue-500), var(--blue-600));
border: 1px solid var(--blue-400);
border-radius: var(--r-sm);
padding: 12px 18px;
color: var(--cream);
font-family: var(--font-body);
font-weight: 600;
cursor: pointer;
}
.primary:disabled { opacity: 0.4; cursor: default; }
.flash { color: var(--danger-500); font-family: var(--font-mono); font-size: var(--text-mono); margin-top: 12px; }
.artifacts { display: flex; flex-direction: column; gap: 8px; }
.artifact-row { display: flex; flex-direction: column; gap: 6px; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 14px 16px; text-decoration: none; color: var(--ink-100); }
.artifact-row:hover { border-color: var(--accent); box-shadow: var(--accent-glow); }
.row-top { display: flex; gap: 12px; align-items: center; }
.artifact-name { color: var(--cream); font-weight: 600; font-size: var(--text-md); }
.row-meta { display: flex; gap: 24px; color: var(--ink-500); font-size: var(--text-mono-sm); }
.mono { font-family: var(--font-mono); }
.tag { font-family: var(--font-mono); font-size: var(--text-xs); padding: 3px 9px; border-radius: var(--r-sm); border: 1px solid transparent; }
.scope-none { background: var(--bg-nav); border-color: var(--border); color: var(--ink-500); }
.scope-game { background: rgba(124, 212, 255, 0.10); border-color: rgba(124, 212, 255, 0.3); color: var(--spark-500); }
.scope-map { background: rgba(255, 176, 32, 0.10); border-color: rgba(255, 176, 32, 0.35); color: var(--amber-500); }
.beta { background: rgba(255, 176, 32, 0.10); border-color: rgba(255, 176, 32, 0.3); color: var(--amber-500); }
.state-untested { background: var(--bg-nav); border-color: var(--border); color: var(--ink-300); }
.state-tested { background: rgba(124, 212, 255, 0.10); border-color: rgba(124, 212, 255, 0.3); color: var(--spark-500); }
.state-test-failed { background: rgba(255, 92, 92, 0.10); border-color: rgba(255, 92, 92, 0.4); color: var(--danger-500); }
.banner { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 4px; border-radius: var(--r-sm); padding: 12px 14px; margin-bottom: 12px; font-size: var(--text-mono); }
.banner-info { background: rgba(124, 212, 255, 0.08); border: 1px solid rgba(124, 212, 255, 0.28); color: var(--ink-100); }
.banner-info a { color: var(--spark-500); text-decoration: underline; }
</style>
+248
View File
@@ -0,0 +1,248 @@
<script lang="ts">
import { onMount } from '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 plugins = $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 } | null>(null);
let newName = $state('');
let newScopeType = $state<'none' | 'game' | 'map'>('none');
let newScopeGame = $state('');
let newScopeMap = $state('');
let newFile = $state<File | null>(null);
let newNotes = $state('');
const scopeValue = $derived.by(() => {
if (newScopeType === 'game') return newScopeGame;
if (newScopeType === 'map') return newScopeMap;
return '';
});
async function load(): Promise<void> {
const [pluginRes, scopeRes] = await Promise.all([
fetch('/api/plugins'),
fetch('/api/scope-options')
]);
plugins = (await pluginRes.json()).scripts;
scopeOptions = (await scopeRes.json()) as ScopeOptions;
loading = false;
}
onMount(load);
function pickFile(e: Event): void {
const t = e.target as HTMLInputElement;
newFile = t.files?.[0] ?? null;
if (!newName && newFile) newName = newFile.name.replace(/\.[^.]+$/, '');
}
async function createPlugin(e: Event): Promise<void> {
e.preventDefault();
if (uploading || !newFile || !newName.trim()) return;
if (newScopeType !== 'none' && !scopeValue) { flash = `pick a ${newScopeType}`; return; }
uploading = true;
flash = null;
const form = new FormData();
form.append('name', newName.trim());
form.append('kind', 'plugin');
form.append('scopeType', newScopeType);
if (scopeValue) form.append('scopeValue', scopeValue);
if (newNotes.trim()) form.append('notes', newNotes.trim());
form.append('content', newFile);
try {
const res = await fetch('/api/plugins', { 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 }
: null;
newName = ''; newScopeType = 'none'; newScopeGame = ''; newScopeMap = ''; newNotes = ''; newFile = null;
await load();
} finally {
uploading = false;
}
}
function scopeLabel(a: ArtifactRow): string {
if (!a.scope_type) return 'unscoped';
return `${a.scope_type}=${a.scope_value ?? '?'}`;
}
function stateTag(a: ArtifactRow): { label: string; cls: string } | null {
if (!a.latestVersion) return null;
if (a.current_version_id === null) return { label: 'untested', cls: 'state-untested' };
if (a.latestVersion.id !== a.current_version_id) {
return { label: `v${a.latestVersion.version} ${a.latestVersion.state}`, cls: `state-${a.latestVersion.state}` };
}
return null;
}
</script>
<h1>Plugins</h1>
<section class="panel">
<h2>Upload a plugin</h2>
{#if successBanner}
<div class="banner banner-info">
<strong>v{successBanner.version} of "{successBanner.name}" uploaded — untested.</strong>
<span>Open a beta on <a href="/betas">the betas page</a> to test it before it can be promoted.</span>
</div>
{/if}
<form onsubmit={createPlugin} class="upload-form">
<label>
<span class="k">name</span>
<input type="text" bind:value={newName} placeholder="my plugin" disabled={uploading} />
</label>
<label>
<span class="k">scope</span>
<div class="scope-row">
<select bind:value={newScopeType} disabled={uploading}>
<option value="none">unscoped</option>
<option value="game">game</option>
<option value="map">map</option>
</select>
{#if newScopeType === 'game'}
<select bind:value={newScopeGame} disabled={uploading}>
<option value="">— pick a game —</option>
{#each scopeOptions.games as g (g)}
<option value={g}>{g}</option>
{/each}
</select>
{:else if newScopeType === 'map'}
<select bind:value={newScopeGame} disabled={uploading}>
<option value="">— pick a game —</option>
{#each scopeOptions.games as g (g)}
<option value={g}>{g}</option>
{/each}
</select>
<select bind:value={newScopeMap} disabled={uploading || !newScopeGame}>
<option value="">— pick a map —</option>
{#each (scopeOptions.mapsByGame[newScopeGame] ?? []) as m (m)}
<option value={m}>{m}</option>
{/each}
</select>
{/if}
</div>
</label>
<label>
<span class="k">notes (optional)</span>
<input type="text" bind:value={newNotes} placeholder="what changed" disabled={uploading} />
</label>
<label>
<span class="k">plugin file (.dll)</span>
<input type="file" accept=".dll" onchange={pickFile} disabled={uploading} />
</label>
<button type="submit" class="primary" disabled={uploading || !newFile || !newName}>
{uploading ? 'uploading…' : 'upload plugin'}
</button>
</form>
{#if flash}<p class="flash">{flash}</p>{/if}
</section>
<section class="panel">
<h2>All plugins</h2>
{#if loading}
<p class="empty">loading…</p>
{:else if plugins.length === 0}
<p class="empty">no plugins yet — upload one above</p>
{:else}
<div class="artifacts">
{#each plugins as a (a.id)}
<a class="artifact-row" href="/scripts/{a.id}">
<div class="row-top">
<span class="artifact-name">{a.name}</span>
<span class="scope tag scope-{a.scope_type ?? 'none'}">{scopeLabel(a)}</span>
{#if stateTag(a)}
{@const t = stateTag(a)!}
<span class="tag {t.cls}">{t.label}</span>
{/if}
{#if a.runningBetaId}
<span class="tag beta">beta {a.runningBetaId} running</span>
{/if}
</div>
<div class="row-meta mono">
<span>{a.target_rel_path}</span>
<span>v{a.latestVersion?.version ?? '—'} · {a.versionCount} version{a.versionCount === 1 ? '' : 's'}</span>
<span>{a.servers.length ? `${a.servers.length} matching server${a.servers.length === 1 ? '' : 's'}` : ''}</span>
</div>
</a>
{/each}
</div>
{/if}
</section>
<style>
h1 { color: var(--cream); font-family: var(--font-display); font-size: var(--text-3xl); letter-spacing: var(--tracking-display); line-height: var(--leading-tight); margin: 0 0 28px; }
.panel { background: var(--bg-nav); border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--pad-panel); margin-bottom: 20px; }
h2 { margin: 0 0 14px; font-family: var(--font-body); font-size: var(--text-xs); font-weight: 700; text-transform: uppercase; letter-spacing: 1.5px; color: var(--ink-300); }
.empty { color: var(--ink-500); font-family: var(--font-mono); font-size: var(--text-mono); margin: 0; }
.upload-form { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; }
.upload-form label { display: flex; flex-direction: column; gap: 6px; font-size: var(--text-xs); }
.upload-form label .k { color: var(--ink-500); text-transform: uppercase; letter-spacing: 1px; }
.upload-form input[type=text], .upload-form select, .upload-form input[type=file] {
background: var(--bg-page); color: var(--ink-100); border: 1px solid var(--border);
border-radius: var(--r-sm); padding: 10px 12px; font-family: var(--font-mono); font-size: var(--text-mono);
}
.upload-form input[type=text]:focus, .upload-form select:focus {
outline: none; border-color: var(--accent); box-shadow: var(--accent-glow);
}
.scope-row { display: flex; gap: 8px; flex-wrap: wrap; }
.scope-row select:nth-of-type(1) { flex: 0 0 120px; }
.scope-row select:nth-of-type(2), .scope-row select:nth-of-type(3) { flex: 1; }
.primary {
grid-column: 1 / -1; background: linear-gradient(180deg, var(--blue-500), var(--blue-600));
border: 1px solid var(--blue-400); border-radius: var(--r-sm); padding: 12px 18px;
color: var(--cream); font-family: var(--font-body); font-weight: 600; cursor: pointer;
}
.primary:disabled { opacity: 0.4; cursor: default; }
.flash { color: var(--danger-500); font-family: var(--font-mono); font-size: var(--text-mono); margin-top: 12px; }
.artifacts { display: flex; flex-direction: column; gap: 8px; }
.artifact-row { display: flex; flex-direction: column; gap: 6px; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 14px 16px; text-decoration: none; color: var(--ink-100); }
.artifact-row:hover { border-color: var(--accent); box-shadow: var(--accent-glow); }
.row-top { display: flex; gap: 12px; align-items: center; }
.artifact-name { color: var(--cream); font-weight: 600; font-size: var(--text-md); }
.row-meta { display: flex; gap: 24px; color: var(--ink-500); font-size: var(--text-mono-sm); }
.mono { font-family: var(--font-mono); }
.tag { font-family: var(--font-mono); font-size: var(--text-xs); padding: 3px 9px; border-radius: var(--r-sm); border: 1px solid transparent; }
.scope-none { background: var(--bg-nav); border-color: var(--border); color: var(--ink-500); }
.scope-game { background: rgba(124, 212, 255, 0.10); border-color: rgba(124, 212, 255, 0.3); color: var(--spark-500); }
.scope-map { background: rgba(255, 176, 32, 0.10); border-color: rgba(255, 176, 32, 0.35); color: var(--amber-500); }
.beta { background: rgba(255, 176, 32, 0.10); border-color: rgba(255, 176, 32, 0.3); color: var(--amber-500); }
.state-untested { background: var(--bg-nav); border-color: var(--border); color: var(--ink-300); }
.state-tested { background: rgba(124, 212, 255, 0.10); border-color: rgba(124, 212, 255, 0.3); color: var(--spark-500); }
.state-test-failed { background: rgba(255, 92, 92, 0.10); border-color: rgba(255, 92, 92, 0.4); color: var(--danger-500); }
.banner { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 4px; border-radius: var(--r-sm); padding: 12px 14px; margin-bottom: 12px; font-size: var(--text-mono); }
.banner-info { background: rgba(124, 212, 255, 0.08); border: 1px solid rgba(124, 212, 255, 0.28); color: var(--ink-100); }
.banner-info a { color: var(--spark-500); text-decoration: underline; }
</style>