import "../../../dialect-helpers-DRI5pyY3.mjs";
import "../../../after-B1IIdH3Y.mjs";
import "../../../object-cache-Bok5j2ae.mjs";
import "../../../base64-CmWvODNW.mjs";
import "../../../types-CuW0zWDA.mjs";
import "../../../media-BrXIaMFN.mjs";
import "../../../options-DTTML-Tx.mjs";
import "../../../request-cache-KCNHp_RJ.mjs";
import "../../../loader-CB6YHeul.mjs";
import "../../../settings-zhmdKyJQ.mjs";
import { n as handleSettingsUpdate, t as handleSettingsGet } from "../../../settings-rZyHEcNT.mjs";
import { a as unwrapResult, r as handleError, t as apiError } from "../../../error-CkAseSqZ.mjs";
import { n as parseBody, t as isParseError } from "../../../parse-GmjecGct.mjs";
import { P as settingsUpdateBody } 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";

//#region src/astro/routes/api/settings.ts
const prerender = false;
/**
* GET /_emdash/api/settings
*
* Returns all site settings as a JSON object.
* Unset values are undefined. Media references include resolved URLs.
*/
const GET = async ({ locals }) => {
	const { emdash, user } = locals;
	if (!emdash?.db) return apiError("NOT_CONFIGURED", "EmDash is not initialized", 500);
	const denied = requirePerm(user, "settings:read");
	if (denied) return denied;
	try {
		return unwrapResult(await handleSettingsGet(emdash.db, emdash.storage));
	} catch (error) {
		return handleError(error, "Failed to get settings", "SETTINGS_READ_ERROR");
	}
};
/**
* POST /_emdash/api/settings
*
* Updates site settings. Accepts a partial settings object.
* Merges with existing settings and returns the updated settings.
*/
const POST = async ({ request, locals }) => {
	const { emdash, user } = locals;
	if (!emdash?.db) return apiError("NOT_CONFIGURED", "EmDash is not initialized", 500);
	const denied = requirePerm(user, "settings:manage");
	if (denied) return denied;
	try {
		const body = await parseBody(request, settingsUpdateBody);
		if (isParseError(body)) return body;
		return unwrapResult(await handleSettingsUpdate(emdash.db, emdash.storage, body));
	} catch (error) {
		return handleError(error, "Failed to update settings", "SETTINGS_UPDATE_ERROR");
	}
};

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