import { ah as isAllowedService, p as checkDocker, z as composeStart, n as buildComposeOptions, H as createLogger } from './src-CidJbygh.js';
import { g as getState } from './state-fxN45gBp.js';
import { d as getRequestId, r as requireAdmin, p as parseJsonBody, j as jsonBodyError, 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';

//#region src/routes/admin/containers/up/+server.ts
var logger = createLogger("containers-up");
var POST = async (event) => {
	const requestId = getRequestId(event);
	logger.info("container start request received", { requestId });
	const authError = requireAdmin(event, requestId);
	if (authError) return authError;
	const state = getState();
	const result = await parseJsonBody(event.request);
	if ("error" in result) return jsonBodyError(result, requestId);
	const body = result.data;
	const service = typeof body.service === "string" ? body.service : "";
	logger.info("starting service", {
		requestId,
		service
	});
	if (!isAllowedService(service, state.configDir)) return errorResponse(400, "invalid_service", "Service is not in allowlist", { service }, requestId);
	if ((await checkDocker()).ok) {
		const result = await composeStart([service], buildComposeOptions(state));
		if (result.ok) state.services[service] = "running";
		else return errorResponse(500, "docker_error", `Failed to start service: ${result.stderr}`, { service }, requestId);
	} else state.services[service] = "running";
	return jsonResponse(200, {
		ok: true,
		service,
		status: state.services[service]
	}, requestId);
};

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