import { aD as readAutomationLogs } 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/automations/[name]/log/+server.ts
var SAFE_NAME_RE = /^[a-zA-Z0-9._-]+(?:\.ya?ml)?$/;
var DEFAULT_LIMIT = 50;
var MAX_LIMIT = 500;
var GET = async (event) => {
	const requestId = getRequestId(event);
	const authErr = requireAdmin(event, requestId);
	if (authErr) return authErr;
	const state = getState();
	const rawName = event.params.name ?? "";
	const taskId = rawName.replace(/\.ya?ml$/, "");
	if (!SAFE_NAME_RE.test(rawName) || rawName.includes("..") || rawName.includes("/")) return errorResponse(400, "invalid_input", "name must match /^[a-zA-Z0-9._-]+$/", {}, requestId);
	const limitParam = event.url.searchParams.get("limit");
	let limit = DEFAULT_LIMIT;
	if (limitParam !== null) {
		const parsed = Number.parseInt(limitParam, 10);
		if (!Number.isFinite(parsed) || parsed <= 0) return errorResponse(400, "invalid_input", "limit must be a positive integer", {}, requestId);
		limit = Math.min(parsed, MAX_LIMIT);
	}
	return jsonResponse(200, {
		name: taskId,
		lines: readAutomationLogs(taskId, state.dataDir, limit)
	}, requestId);
};

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