globalThis.process ??= {};
globalThis.process.env ??= {};
import { r as __exportAll } from "./rolldown-runtime_-UtK6b3T.mjs";
import { T as setSetting, W as ContentValidationError, d as mapContentError, h as getAllSettings, u as jsonOk } from "./crypto_CY2zBtG3.mjs";
import { n as getFullDb } from "./db_BQ9NAt8x.mjs";
import { n as recordAudit, t as clientIp } from "./audit_D9EAE4GF.mjs";
import { c as assertCsrf, i as requireAdmin } from "./auth_B0DWM0G6.mjs";
import { env } from "cloudflare:workers";
//#region src/pages/api/admin/settings.ts
var settings_exports = /* @__PURE__ */ __exportAll({
	GET: () => GET,
	PUT: () => PUT,
	prerender: () => false
});
var GET = async ({ request, cookies }) => {
	try {
		const { actor, authMode } = await requireAdmin(request, env, cookies);
		const { db } = getFullDb(env);
		const settings = await getAllSettings(db);
		return jsonOk(settings);
	} catch (error) {
		return mapContentError(error);
	}
};
var PUT = async ({ request, cookies }) => {
	try {
		const { actor, authMode } = await requireAdmin(request, env, cookies);
		assertCsrf(request, {
			authMode,
			siteOrigin: env.SITE_ORIGIN
		});
		const { db } = getFullDb(env);
		const data = await request.json();
		if (typeof data !== "object" || data === null) throw new ContentValidationError("input", "must be an object");
		const raw = data;
		if (typeof raw.key !== "string" || !raw.key.trim()) throw new ContentValidationError("key", "required string");
		await setSetting(db, raw.key, raw.value);
		await recordAudit(db, {
			actorId: actor.id,
			ip: clientIp(request)
		}, {
			action: "settings.update",
			entityType: "settings",
			entityId: raw.key
		});
		return jsonOk({ ok: true });
	} catch (error) {
		return mapContentError(error);
	}
};
//#endregion
//#region \0virtual:astro:page:src/pages/api/admin/settings@_@ts
var page = () => settings_exports;
//#endregion
export { page };
