mirror of
https://github.com/Patiun/com.gregkilmer.www.git
synced 2026-11-08 04:08:24 +00:00
e3b0cf60c5
- Sync scheduler in the content service with a per-job cache (sync_cache), sync_runs reporting and Healthchecks pings. Jobs: Archidekt, BoardGameGeek, cover art (Open Library, TMDB, AniList), Suwayomi and Kavita reading progress, Bambuddy filament and Homebox material stock. A note's own value always wins over a synced one. - PersonalReader: updates only Library notes with a matching anilistId, changes to Greg's notes are held for review; Reading series with no note show as suggestions on the admin Overview. - /api/inquiries and /api/orders: Turnstile, rate limits, a saved copy in the content service (intake token) plus email over SMTP. Orders are re-checked against the live notes: accepted only when the category's ordersOpen is true and the line has capacity. - Admin Inbox for saved submissions. Options' inStock is optional so synced stock can fill it. All settings from process.env; .env.example per service. - Sources could not be reached from the build environment; parsers are tested against fixtures labelled as not live. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012aSbo2D1qP8cMFQCykf7kx
47 lines
1.8 KiB
TypeScript
47 lines
1.8 KiB
TypeScript
/**
|
|
* Sync settings from the environment. A job is enabled only when its config
|
|
* is present: the public sources (no credentials) are named in SYNC_JOBS;
|
|
* jobs that need a URL or a login are enabled by those variables alone.
|
|
*/
|
|
import { homelabSettings, type HomelabSettings } from "./jobs/homelab.ts";
|
|
|
|
export interface SyncSettings {
|
|
/** Public jobs switched on in SYNC_JOBS, e.g. "archidekt,bgg,covers". */
|
|
enabled: Set<string>;
|
|
/** SYNC_<JOB>_MINUTES overrides a job's interval. */
|
|
minutes: Record<string, number>;
|
|
/** SYNC_<JOB>_HEALTHCHECK_URL. */
|
|
healthchecks: Record<string, string>;
|
|
bggToken?: string;
|
|
tmdbApiKey?: string;
|
|
/** Suwayomi, Kavita, Bambuddy and Homebox: enabled by their own URL and login. */
|
|
homelab: HomelabSettings;
|
|
}
|
|
|
|
const envKey = (job: string) => job.toUpperCase().replace(/[^A-Z0-9]/g, "_");
|
|
|
|
export function syncSettings(env: NodeJS.ProcessEnv = process.env): SyncSettings {
|
|
const enabled = new Set((env.SYNC_JOBS ?? "").split(",").map((s) => s.trim().toLowerCase()).filter(Boolean));
|
|
const minutes: Record<string, number> = {};
|
|
const healthchecks: Record<string, string> = {};
|
|
for (const [k, v] of Object.entries(env)) {
|
|
if (!v) continue;
|
|
const m = /^SYNC_([A-Z0-9_]+)_(MINUTES|HEALTHCHECK_URL)$/.exec(k);
|
|
if (!m) continue;
|
|
const job = m[1]!.toLowerCase().replace(/_/g, "-");
|
|
if (m[2] === "MINUTES" && Number(v) > 0) minutes[job] = Number(v);
|
|
if (m[2] === "HEALTHCHECK_URL") healthchecks[job] = v;
|
|
}
|
|
return {
|
|
enabled,
|
|
minutes,
|
|
healthchecks,
|
|
bggToken: env.BGG_TOKEN || undefined,
|
|
tmdbApiKey: env.TMDB_API_KEY || undefined,
|
|
homelab: homelabSettings(env),
|
|
};
|
|
}
|
|
|
|
/** The env var name for one job's setting, for docs and messages. */
|
|
export const syncEnvName = (job: string, what: "MINUTES" | "HEALTHCHECK_URL") => `SYNC_${envKey(job)}_${what}`;
|