import { ag as inspectInstallLock, I as INSTALL_LOCK_STALE_AFTER_MS, b5 as unlockInstallLock, H as createLogger } from './src-CidJbygh.js';
import { g as getState } from './state-fxN45gBp.js';
import { d as getRequestId, r as requireAdmin, k as jsonResponse, e as errorResponse } 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/unlock/+server.ts
var logger = createLogger("unlock-admin");
/**
* #500 — "an operation seems stuck — clear it?" Reports whether an install lock
* is present and whether it is stale (so the UI can decide whether to offer the
* clear action). Read-only.
*/
var GET = async (event) => {
	const requestId = getRequestId(event);
	const authError = requireAdmin(event, requestId);
	if (authError) return authError;
	const state = getState();
	try {
		return jsonResponse(200, {
			ok: true,
			staleAfterMs: INSTALL_LOCK_STALE_AFTER_MS,
			...inspectInstallLock(state.dataDir)
		}, requestId);
	} catch (e) {
		return errorResponse(500, "unlock_status_failed", e instanceof Error ? e.message : String(e), {}, requestId);
	}
};
/**
* #500 — clears the install lock ONLY when stale (dead holder PID or older than
* the 30-minute staleness window). Returns 409 when a live install is still
* holding the lock so the UI can surface "an operation is still running" rather
* than forcing it. Never blind-removes a live lock.
*/
var POST = async (event) => {
	const requestId = getRequestId(event);
	const authError = requireAdmin(event, requestId);
	if (authError) return authError;
	const state = getState();
	try {
		const result = unlockInstallLock(state.dataDir);
		if (!result.ok) return errorResponse(409, "install_in_progress", "An install or upgrade still appears to be running. The lock clears itself automatically once it finishes or after 30 minutes. Nothing was changed.", { status: result.status }, requestId);
		logger.info("cleared install lock via admin", {
			requestId,
			removed: result.removed
		});
		return jsonResponse(200, {
			ok: true,
			removed: result.removed,
			status: result.status
		}, requestId);
	} catch (e) {
		return errorResponse(500, "unlock_failed", e instanceof Error ? e.message : String(e), {}, requestId);
	}
};

export { GET, POST };
//# sourceMappingURL=_server.ts--pU-mhOv.js.map
