Refresh script library with batch uploads and beta handoff
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
import { onMount, onDestroy } from 'svelte';
|
||||
import { artifactVersionLabel } from '$lib/artifact-version.js';
|
||||
import { goto } from '$app/navigation';
|
||||
import { parseBetaSelection } from '$lib/script-library.js';
|
||||
import Card from '$ui/components/primitives/Card.svelte';
|
||||
import Badge from '$ui/components/primitives/Badge.svelte';
|
||||
import Button from '$ui/components/primitives/Button.svelte';
|
||||
@@ -61,6 +62,7 @@
|
||||
fetch('/api/scripts'),
|
||||
fetch('/api/servers')
|
||||
]);
|
||||
if (!betasRes.ok || !scriptsRes.ok || !serversRes.ok) throw new Error('Could not load beta setup. Refresh to try again.');
|
||||
const bBody = (await betasRes.json()) as { betas: BetaListRow[] };
|
||||
betas = bBody.betas;
|
||||
if (scriptsRes.ok) {
|
||||
@@ -71,7 +73,6 @@
|
||||
const svBody = (await serversRes.json()) as { servers: ServerRow[] };
|
||||
fleetServers = svBody.servers;
|
||||
}
|
||||
loading = false;
|
||||
}
|
||||
async function refreshBetas(): Promise<void> {
|
||||
const res = await fetch('/api/betas');
|
||||
@@ -82,7 +83,7 @@
|
||||
|
||||
let poll: ReturnType<typeof setInterval> | null = null;
|
||||
onMount(() => {
|
||||
void load().then(seedImportedPlugin).catch(error => { flash = (error as Error).message; });
|
||||
void load().then(seedSelection).catch(error => { flash = (error as Error).message; }).finally(() => { loading = false; });
|
||||
poll = setInterval(refreshBetas, 5000);
|
||||
});
|
||||
onDestroy(() => {
|
||||
@@ -91,7 +92,8 @@
|
||||
|
||||
const eligibleScripts = $derived(
|
||||
scripts.filter(
|
||||
(s) => s.runningBetaId === null && s.latestVersion !== null && s.latestVersion.id !== s.current_version_id
|
||||
(s) => s.runningBetaId === null && s.latestVersion !== null && (s.latestVersion.id !== s.current_version_id
|
||||
|| picks.some(p => p.scriptId === s.id && p.versionId !== null && p.versionId !== s.current_version_id))
|
||||
)
|
||||
);
|
||||
|
||||
@@ -102,24 +104,26 @@
|
||||
return eligibleScripts.filter((s) => !takenIds.has(s.id));
|
||||
}
|
||||
|
||||
async function seedImportedPlugin(): Promise<void> {
|
||||
async function seedSelection(): Promise<void> {
|
||||
const query = new URLSearchParams(window.location.search);
|
||||
if (!query.has('pluginId')) return;
|
||||
const pluginId = Number(query.get('pluginId'));
|
||||
const versionId = Number(query.get('versionId'));
|
||||
if (!eligibleScripts.some(s => s.id === pluginId && s.kind === 'plugin')) {
|
||||
flash = 'This plugin is already promoted or has a running beta. Open its detail page to review its status.';
|
||||
return;
|
||||
const selections = parseBetaSelection(query);
|
||||
if (!selections.length) return;
|
||||
// Validate all selections before populating; never substitute a newer upload.
|
||||
const details = await Promise.all(selections.map(async ({ scriptId, versionId }) => {
|
||||
const res = await fetch(`/api/scripts/${scriptId}`);
|
||||
if (!res.ok) throw new Error('A selected artifact is no longer available. Choose artifacts below.');
|
||||
const detail = await res.json() as ScriptDetail & { runningBetaId: number | null };
|
||||
if (detail.runningBetaId !== null || detail.script.current_version_id === versionId
|
||||
|| !detail.versions.some(v => v.id === versionId)) {
|
||||
throw new Error(`${detail.script.name}: the selected version is already promoted, unavailable, or in an active beta. Review your selection below.`);
|
||||
}
|
||||
return detail;
|
||||
}));
|
||||
for (const detail of details) {
|
||||
detailById[detail.script.id] = detail;
|
||||
}
|
||||
picks = [{ key: nextKey++, scriptId: pluginId, versionId: null }];
|
||||
await onPickScript(0);
|
||||
if (!versionsForRow(picks[0]).some(v => v.id === versionId)) {
|
||||
picks[0].versionId = null;
|
||||
flash = 'The imported version is no longer available for testing. Choose a version to continue.';
|
||||
return;
|
||||
}
|
||||
picks[0].versionId = versionId;
|
||||
picks = [...picks];
|
||||
picks = selections.map(s => ({ key: nextKey++, ...s }));
|
||||
pickedServers = new Set();
|
||||
}
|
||||
|
||||
async function onPickScript(rowIdx: number): Promise<void> {
|
||||
@@ -246,6 +250,8 @@
|
||||
subtitle="Test unpromoted versions on selected servers before rolling them out."
|
||||
/>
|
||||
|
||||
{#if flash}<p class="flash" role="alert">{flash}</p>{/if}
|
||||
|
||||
{#if loading}
|
||||
<div class="loading">Loading…</div>
|
||||
{:else}
|
||||
@@ -336,7 +342,6 @@
|
||||
>
|
||||
Open beta
|
||||
</Button>
|
||||
{#if flash}<span class="flash">{flash}</span>{/if}
|
||||
</div>
|
||||
</form>
|
||||
{/if}
|
||||
|
||||
Reference in New Issue
Block a user