[modularization] Phase 2: Extract data layer — gitea, weather, bitcoin, loaders (#460)
Some checks failed
Deploy Nexus / deploy (push) Failing after 4s
Staging Smoke Test / smoke-test (push) Failing after 0s

This commit was merged in pull request #460.
This commit is contained in:
2026-03-24 21:28:03 +00:00
parent d201d3e6a9
commit 764b617a2a
11 changed files with 280 additions and 163 deletions

45
modules/data/loaders.js Normal file
View File

@@ -0,0 +1,45 @@
// 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' };
}
}