import { aR as resolveDataDir, b0 as seedUiBuild, H as createLogger } from './src-CidJbygh.js';
import { d as getRequestId, r as requireAdmin, e as errorResponse, k as jsonResponse } from './helpers-kzwksNq1.js';
import './chunk-CLZ62Ad-.js';
import 'node:module';
import './provider-constants-DPrj3yBX.js';
import './dist-DOFcG0Zp.js';
import 'node:fs';
import 'node:path';
import 'buffer';
import 'fs';
import 'path';
import 'node:child_process';
import 'node:url';
import 'node:crypto';
import 'events';
import 'node:events';
import 'node:stream';
import 'node:string_decoder';
import 'assert';
import 'zlib';
import 'node:assert';
import 'node:fs/promises';
import 'node:os';
import './endpoints-UdQGgKsR.js';
import './state-fxN45gBp.js';

//#region src/routes/admin/ui-version/+server.ts
var logger = createLogger("ui-version");
var POST = async (event) => {
	const requestId = getRequestId(event);
	const authError = requireAdmin(event, requestId);
	if (authError) return authError;
	let body;
	try {
		body = await event.request.json();
	} catch {
		return errorResponse(400, "invalid_json", "Request body must be valid JSON", {}, requestId);
	}
	const tag = typeof body.tag === "string" ? body.tag.trim() : "";
	if (!tag) return errorResponse(400, "tag_required", "tag is required", {}, requestId);
	if (!/^[a-zA-Z0-9._\-]+$/.test(tag)) return errorResponse(400, "invalid_tag", "Tag must be alphanumeric with . _ or - only", {}, requestId);
	const dataDir = resolveDataDir();
	const repoRef = tag.startsWith("v") ? tag : `v${tag}`;
	try {
		await seedUiBuild(repoRef, dataDir, { forceRemote: true });
	} catch (e) {
		const msg = e instanceof Error ? e.message : String(e);
		logger.error("ui-version download failed", {
			requestId,
			error: msg
		});
		return errorResponse(502, "download_failed", msg, { message: msg }, requestId);
	}
	const supervisor = process.env.OP_UI_SUPERVISOR ?? "";
	let restarting = false;
	if (supervisor && process.ppid && process.ppid > 1) try {
		process.kill(process.ppid, "SIGUSR2");
		restarting = true;
		logger.info("ui-version restart signalled", {
			requestId,
			supervisor,
			ppid: process.ppid
		});
	} catch (e) {
		logger.warn("ui-version restart signal failed", {
			requestId,
			error: e instanceof Error ? e.message : String(e)
		});
	}
	logger.info("ui-version downloaded", {
		requestId,
		tag,
		restarting
	});
	return jsonResponse(200, {
		ok: true,
		tag,
		restarting
	}, requestId);
};

export { POST };
//# sourceMappingURL=_server.ts-BE9SHXNP.js.map
