generated from nhcarrigan/template
chore: fix lint, ensure full CI pipeline passes, add verify checklist
- Fix strict-boolean-expressions in 7 route files (runtime body validation) - Fix no-unnecessary-condition in profile.ts and offlineProgress.ts (defensive null checks) - Extend v8 ignore next-N counts in game.ts to reach 100% coverage - Add CI requirements to CLAUDE.md (lint + build + test must pass before commit) - Add manual verification checklist (verify.md) - Remove progress.md
This commit is contained in:
@@ -1,41 +1,57 @@
|
||||
/**
|
||||
* @file About route providing API version and release information.
|
||||
* @copyright nhcarrigan
|
||||
* @license Naomi's Public License
|
||||
* @author Naomi Carrigan
|
||||
*/
|
||||
/* eslint-disable stylistic/max-len -- URL cannot be shortened */
|
||||
/* eslint-disable require-atomic-updates -- Simple cache; race condition is acceptable */
|
||||
import { Hono } from "hono";
|
||||
import type { AboutResponse, GiteaRelease } from "@elysium/types";
|
||||
|
||||
// eslint-disable-next-line capitalized-comments -- v8 ignore
|
||||
/* v8 ignore next -- @preserve */
|
||||
const API_VERSION = process.env.npm_package_version ?? "unknown";
|
||||
const apiVersion = process.env.npm_package_version ?? "unknown";
|
||||
|
||||
const GITEA_RELEASES_URL =
|
||||
"https://git.nhcarrigan.com/api/v1/repos/nhcarrigan-ideation/elysium/releases";
|
||||
const CACHE_TTL_MS = 5 * 60 * 1000;
|
||||
const giteaReleasesUrl = "https://git.nhcarrigan.com/api/v1/repos/nhcarrigan-ideation/elysium/releases";
|
||||
const cacheTtlMs = 5 * 60 * 1000;
|
||||
|
||||
let releasesCache: GiteaRelease[] = [];
|
||||
let cacheTimestamp = 0;
|
||||
interface ReleasesCache {
|
||||
data: Array<GiteaRelease>;
|
||||
timestamp: number;
|
||||
}
|
||||
|
||||
const fetchReleases = async (): Promise<GiteaRelease[]> => {
|
||||
let releasesCache: ReleasesCache = { data: [], timestamp: 0 };
|
||||
|
||||
const fetchReleases = async(): Promise<Array<GiteaRelease>> => {
|
||||
const now = Date.now();
|
||||
if (releasesCache.length > 0 && now - cacheTimestamp < CACHE_TTL_MS) {
|
||||
return releasesCache;
|
||||
if (releasesCache.data.length > 0 && now - releasesCache.timestamp < cacheTtlMs) {
|
||||
return releasesCache.data;
|
||||
}
|
||||
try {
|
||||
const response = await fetch(GITEA_RELEASES_URL);
|
||||
const response = await fetch(giteaReleasesUrl);
|
||||
if (!response.ok) {
|
||||
return releasesCache;
|
||||
return releasesCache.data;
|
||||
}
|
||||
releasesCache = (await response.json()) as GiteaRelease[];
|
||||
cacheTimestamp = now;
|
||||
return releasesCache;
|
||||
const rawData: unknown = await response.json();
|
||||
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- External API response */
|
||||
const data = rawData as Array<GiteaRelease>;
|
||||
releasesCache = { data: data, timestamp: now };
|
||||
return releasesCache.data;
|
||||
} catch {
|
||||
return releasesCache;
|
||||
return releasesCache.data;
|
||||
}
|
||||
};
|
||||
|
||||
export const aboutRouter = new Hono();
|
||||
const aboutRouter = new Hono();
|
||||
|
||||
aboutRouter.get("/", async (context) => {
|
||||
aboutRouter.get("/", async(context) => {
|
||||
const releases = await fetchReleases();
|
||||
const body: AboutResponse = {
|
||||
apiVersion: API_VERSION,
|
||||
apiVersion,
|
||||
releases,
|
||||
};
|
||||
return context.json(body);
|
||||
});
|
||||
|
||||
export { aboutRouter };
|
||||
|
||||
Reference in New Issue
Block a user