Created modules/data/ with 4 data modules: - data/gitea.js: Centralized Gitea API (commits, PRs, agent status) - data/weather.js: Open-Meteo weather data fetch - data/bitcoin.js: Blockstream block height polling - data/loaders.js: Static file loaders (portals.json, sovereignty-status.json, SOUL.md) Updated consumers to use data modules instead of direct fetch(): - panels.js: Uses data/gitea.js for agent status - heatmap.js: Uses data/gitea.js for commit data - extras.js: Uses data/gitea.js for timelapse, data/bitcoin.js for block height - portals.js: Uses data/loaders.js for portals.json - effects.js: Uses data/loaders.js for sovereignty-status.json - oath.js: Uses data/loaders.js for SOUL.md - audio.js: Uses data/loaders.js for SOUL.md Deduplication wins: - Gitea token centralized (was hardcoded in 3 files) - SOUL.md now cached (was fetched 3x independently) - Nexus commits shared cache (was fetched 2x independently) Refs #421
46 lines
1.5 KiB
JavaScript
46 lines
1.5 KiB
JavaScript
// modules/data/loaders.js — Static file loaders (portals.json, sovereignty-status.json, SOUL.md)
|
|
// Writes to S: sovereigntyScore, sovereigntyLabel
|
|
import { S } from '../state.js';
|
|
|
|
// --- SOUL.md (cached) ---
|
|
let _soulMdCache = null;
|
|
|
|
export async function fetchSoulMd() {
|
|
if (_soulMdCache) return _soulMdCache;
|
|
try {
|
|
const res = await fetch('SOUL.md');
|
|
if (!res.ok) throw new Error('not found');
|
|
const raw = await res.text();
|
|
_soulMdCache = raw.split('\n').slice(1).map(l => l.replace(/^#+\s*/, ''));
|
|
return _soulMdCache;
|
|
} catch {
|
|
return ['I am Timmy.', '', 'I am sovereign.', '', 'This Nexus is my home.'];
|
|
}
|
|
}
|
|
|
|
// --- portals.json ---
|
|
export async function fetchPortals() {
|
|
const res = await fetch('./portals.json');
|
|
if (!res.ok) throw new Error('Portals not found');
|
|
return await res.json();
|
|
}
|
|
|
|
// --- sovereignty-status.json ---
|
|
export async function fetchSovereigntyStatus() {
|
|
try {
|
|
const res = await fetch('./sovereignty-status.json');
|
|
if (!res.ok) throw new Error('not found');
|
|
const data = await res.json();
|
|
const score = Math.max(0, Math.min(100, typeof data.score === 'number' ? data.score : 85));
|
|
const label = typeof data.label === 'string' ? data.label : '';
|
|
const assessmentType = data.assessment_type || 'MANUAL';
|
|
|
|
S.sovereigntyScore = score;
|
|
S.sovereigntyLabel = label;
|
|
|
|
return { score, label, assessmentType };
|
|
} catch {
|
|
return { score: S.sovereigntyScore, label: S.sovereigntyLabel, assessmentType: 'MANUAL' };
|
|
}
|
|
}
|