import "../../../../../dialect-helpers-DRI5pyY3.mjs";
import "../../../../../base64-CmWvODNW.mjs";
import "../../../../../types-CuW0zWDA.mjs";
import "../../../../../options-DTTML-Tx.mjs";
import "../../../../../redirect-IyfNirgS.mjs";
import { a as unwrapResult, i as requireDb, r as handleError } from "../../../../../error-CkAseSqZ.mjs";
import { i as parseQuery, n as parseBody, t as isParseError } from "../../../../../parse-GmjecGct.mjs";
import { a as notFoundPruneBody, r as notFoundListQuery } from "../../../../../redirects-DXEXBAII.mjs";
import "../../../../../byline-fields-2Lp5Hbgf.mjs";
import "../../../../../status-CqJQX1QN.mjs";
import "../../../../../api/schemas/index.mjs";
import { n as requirePerm } from "../../../../../authorize-Dz88F_Fw.mjs";
import { n as handleNotFoundList, r as handleNotFoundPrune, t as handleNotFoundClear } from "../../../../../redirects-Bs1g42Ri.mjs";

//#region src/astro/routes/api/redirects/404s/index.ts
const prerender = false;
const GET = async ({ url, locals }) => {
	const { emdash, user } = locals;
	const dbErr = requireDb(emdash?.db);
	if (dbErr) return dbErr;
	const db = emdash.db;
	const denied = requirePerm(user, "redirects:read");
	if (denied) return denied;
	try {
		const query = parseQuery(url, notFoundListQuery);
		if (isParseError(query)) return query;
		return unwrapResult(await handleNotFoundList(db, query));
	} catch (error) {
		return handleError(error, "Failed to fetch 404 log", "NOT_FOUND_LIST_ERROR");
	}
};
const DELETE = async ({ locals }) => {
	const { emdash, user } = locals;
	const dbErr = requireDb(emdash?.db);
	if (dbErr) return dbErr;
	const db = emdash.db;
	const denied = requirePerm(user, "redirects:manage");
	if (denied) return denied;
	try {
		return unwrapResult(await handleNotFoundClear(db));
	} catch (error) {
		return handleError(error, "Failed to clear 404 log", "NOT_FOUND_CLEAR_ERROR");
	}
};
const POST = async ({ request, locals }) => {
	const { emdash, user } = locals;
	const dbErr = requireDb(emdash?.db);
	if (dbErr) return dbErr;
	const db = emdash.db;
	const denied = requirePerm(user, "redirects:manage");
	if (denied) return denied;
	try {
		const body = await parseBody(request, notFoundPruneBody);
		if (isParseError(body)) return body;
		return unwrapResult(await handleNotFoundPrune(db, body.olderThan));
	} catch (error) {
		return handleError(error, "Failed to prune 404 log", "NOT_FOUND_PRUNE_ERROR");
	}
};

//#endregion
export { DELETE, GET, POST, prerender };
//# sourceMappingURL=index.mjs.map