import { j as json } from './exports-D1quPX8S.js';
import { r as requireAdmin, d as getRequestId } from './helpers-kzwksNq1.js';
import { i as invalidateVersionCache, w as withCache } from './version-cache-CSnmLqxQ.js';
import './utils-BSRjJDrZ.js';
import './src-CidJbygh.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';
import './state-fxN45gBp.js';

//#region src/lib/server/release-units.ts
var ELECTRON_ASSET_PATTERN = /^OpenPalm-.*\.(dmg|AppImage|zip|deb|rpm|pkg)$/i;
var PLATFORM_TAG_PATTERN = /^platform-(\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]*)?)$/;
var LEGACY_V_TAG_PATTERN = /^v(\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]*)?)$/;
/**
* Select only platform releases that carry installable app assets (Electron
* installer or skeleton/deploy bundle), skipping per-unit container-image
* releases.
*
* Per-unit version pickers now read from Docker Hub tags (not GitHub releases),
* so the releases endpoint only needs app-level releases — the ones with
* downloadable installer/bundle assets. This dramatically reduces the data the
* UI holds and keeps the GitHub API call to its existing single request (the
* filtering is client-side of the fetch, not a second fetch).
*
* Deduplicates by semver so `{#each r.tag}` keys stay unique when a platform
* release created both a `platform-X.Y.Z` and a legacy `vX.Y.Z` tag. Preserves
* GitHub's `created_at` desc ordering.
*/
function selectInstallableReleases(raw) {
	const seen = /* @__PURE__ */ new Set();
	const releases = [];
	for (const r of raw) {
		const hasElectronBuild = r.assets.some((a) => ELECTRON_ASSET_PATTERN.test(a.name));
		if (!hasElectronBuild) continue;
		const platformMatch = r.tag_name.match(PLATFORM_TAG_PATTERN);
		if (platformMatch) {
			const tag = platformMatch[1];
			if (!seen.has(tag)) {
				seen.add(tag);
				releases.push({
					tag,
					prerelease: r.prerelease,
					publishedAt: r.published_at,
					hasElectronBuild
				});
			}
			continue;
		}
		const legacyMatch = r.tag_name.match(LEGACY_V_TAG_PATTERN);
		if (legacyMatch) {
			const tag = legacyMatch[1];
			if (!seen.has(tag)) {
				seen.add(tag);
				releases.push({
					tag,
					prerelease: r.prerelease,
					publishedAt: r.published_at,
					hasElectronBuild
				});
			}
			continue;
		}
	}
	return releases;
}
//#endregion
//#region src/routes/admin/versions/releases/+server.ts
var CACHE_KEY = "github:releases";
var GET = async (event) => {
	const authError = requireAdmin(event, getRequestId(event));
	if (authError) return authError;
	if (event.url.searchParams.get("refresh") === "1") invalidateVersionCache();
	const cached = await withCache(CACHE_KEY, async () => {
		const res = await fetch("https://api.github.com/repos/itlackey/openpalm/releases?per_page=20", {
			headers: {
				"User-Agent": "openpalm-admin/1.0",
				Accept: "application/vnd.github+json"
			},
			signal: AbortSignal.timeout(8e3)
		});
		if (!res.ok) throw new Error(`GitHub API ${res.status}`);
		return selectInstallableReleases(await res.json());
	});
	if (cached !== void 0) return json({ releases: cached });
	return json({
		releases: [],
		error: "GitHub releases unavailable"
	});
};

export { GET };
//# sourceMappingURL=_server.ts-CEarW7QY.js.map
