globalThis.process ??= {};
globalThis.process.env ??= {};
import { r as __exportAll } from "./rolldown-runtime_-UtK6b3T.mjs";
import { env } from "cloudflare:workers";
//#region src/lib/timing-safe.ts
/**
* Constant-time string equality (web-standard; no Node `crypto.timingSafeEqual` on Workers).
* Length difference is folded into the accumulator — NO early return on length mismatch,
* so comparison time does not leak the secret's length.
*/
function timingSafeEqualStr(a, b) {
	const enc = new TextEncoder();
	const ab = enc.encode(a);
	const bb = enc.encode(b);
	let diff = ab.length ^ bb.length;
	const max = Math.max(ab.length, bb.length);
	for (let i = 0; i < max; i++) diff |= (ab[i] ?? 0) ^ (bb[i] ?? 0);
	return diff === 0;
}
//#endregion
//#region src/pages/cron-arm.ts
var cron_arm_exports = /* @__PURE__ */ __exportAll({
	POST: () => POST,
	prerender: () => false
});
var POST = async ({ request }) => {
	const provided = request.headers.get("x-mod-cron-secret") ?? "";
	const expected = env.CRON_DO_SECRET ?? "";
	if (expected.length === 0 || !timingSafeEqualStr(provided, expected)) return new Response("forbidden", { status: 403 });
	if (!env.SCHEDULED_PUBLISH_DO) return new Response("durable object binding unavailable (local dev)", { status: 503 });
	const id = env.SCHEDULED_PUBLISH_DO.idFromName("scheduled-publish");
	const stub = env.SCHEDULED_PUBLISH_DO.get(id);
	try {
		const res = await stub.fetch("https://do/arm", {
			method: "POST",
			headers: { "x-mod-cron-secret": provided }
		});
		return new Response(await res.text(), { status: res.status });
	} catch (err) {
		console.error("[cron-arm] DO fetch failed:", err instanceof Error ? err.message : String(err));
		return new Response("durable object unreachable", { status: 502 });
	}
};
//#endregion
//#region \0virtual:astro:page:src/pages/cron-arm@_@ts
var page = () => cron_arm_exports;
//#endregion
export { page };
