config and plugin
This commit is contained in:
@@ -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>
|
||||
Reference in New Issue
Block a user