import { ah as isAllowedService, p as checkDocker, u as composeLogs, n as buildComposeOptions } from './src-CidJbygh.js';
import { g as getState } from './state-fxN45gBp.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';

//#region src/routes/admin/logs/+server.ts
var GET = async (event) => {
	const requestId = getRequestId(event);
	const authError = requireAdmin(event, requestId);
	if (authError) return authError;
	const state = getState();
	const url = new URL(event.request.url);
	const serviceParam = url.searchParams.get("service");
	const tailParam = url.searchParams.get("tail");
	const sinceParam = url.searchParams.get("since");
	const tail = tailParam ? Number(tailParam) : 100;
	if (tailParam && (!Number.isInteger(tail) || tail < 1 || tail > 1e4)) return errorResponse(400, "invalid_parameter", "tail must be an integer between 1 and 10000", {}, requestId);
	let services;
	if (serviceParam) {
		services = serviceParam.split(",").map((s) => s.trim()).filter(Boolean);
		const invalid = services.filter((s) => !isAllowedService(s, state.configDir));
		if (invalid.length > 0) return errorResponse(400, "invalid_service", `Invalid service name(s): ${invalid.join(", ")}`, { invalid }, requestId);
	}
	if (sinceParam && !/^[a-zA-Z0-9.:+\-T]+$/.test(sinceParam)) return errorResponse(400, "invalid_parameter", "since contains invalid characters", {}, requestId);
	if (!(await checkDocker()).ok) return errorResponse(503, "docker_unavailable", "Docker is not available", {}, requestId);
	const result = await composeLogs(services, tail, {
		...buildComposeOptions(state),
		since: sinceParam ?? void 0
	});
	if (!result.ok) return jsonResponse(500, {
		ok: false,
		logs: "",
		error: result.stderr
	}, requestId);
	return jsonResponse(200, {
		ok: true,
		logs: (result.stdout + result.stderr).trim()
	}, requestId);
};

export { GET };
//# sourceMappingURL=_server.ts-DBIVm5KK.js.map
