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