Something went wrong. Try again.
Web frontend and supporting services for lance.blue
Something went wrong. Try again.
2.1 kB · 52 lines
TypeScript
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253/** * Which unit library this page reads. */
import { apiVersion } from "./api";import { HELM_RELEASE, MEGAMEK_VERSION } from "./megamek";
/** * Which library to read, asked of the API rather than compiled in. * * `megamek.ts`'s constants are a fallback and nothing more. helm publishes under a * prefix named for its own release, and this file naming one meant a helm * deploy needed a site build to match it - which it did not always get, and * then the force builder and the match reports read different indexes with * nothing to say so. The API loads an index and reports what it loaded, so * asking it is what makes the two agree. * * `/api/version` is already fetched once per page load for the footer, and * `apiVersion` shares that one promise, so this costs no request of its own. * * Its own module rather than part of `megamek.ts`, because that file is * imported by tests that run under plain `node --test`: it builds addresses * and nothing else, and giving it an import of `api.ts` broke every one of * them at once. */export async function library(): Promise<Library> { // An unreachable API, or one with no index, is not a reason to show no // designs at all: the constants are the last release this build knew // about, and helm never deletes a prefix, so they still resolve. const info = await apiVersion(); return { helm: info?.library?.helm ?? HELM_RELEASE, megamek: info?.library?.megamek ?? MEGAMEK_VERSION, read: Boolean(info?.library), };}
/** Which library to read, and whether the API is reading it too. */export interface Library { helm: string; megamek: string; /** * Whether the API loaded an index of its own. * * False is not a detail: the endpoints that answer out of it answer with * nothing rather than with an error, so a caller that only fails over on a * failed request would take that silence for an answer. A screen that has * a second way to the same column - `unit-art.ts` reads the index itself - * takes it when this is false. */ read: boolean;}