S1: Einrichtungs-Assistent, Twitch-Auth, Datenbank und Chat-Aufnahme
Zugangsdaten kommen jetzt aus der App statt aus einer .env: ein Einrichtungs-Assistent auf http://localhost:4792/setup nimmt Client-ID, Secret und OBS-Passwort entgegen, der OAuth-Rueckruf laeuft auf denselben Server. Gespeichert wird verschlueselt (AES-256-GCM) in einem Volume, bewusst nicht in der Datenbank - die wird auf die Windows-Seite gesichert. Siehe ADR-0005. Technikbasis vereinfacht: Node 24 bringt node:sqlite, WebSocket, fetch und die Ausfuehrung von TypeScript mit. Das Projekt hat damit null Laufzeitabhaengigkeiten und keinen Build-Schritt; pnpm-Workspaces und die Paketmanifeste sind entfallen, Importe laufen ueber die imports-Map der Wurzel-package.json. erasableSyntaxOnly verhindert Syntax, die das Type Stripping stillschweigend entfernen wuerde. Siehe Nachtrag 2 in ADR-0001. Enthalten: - packages/core: Config, Layout, Logger mit Secret-Maskierung, Retry, YAML - packages/db: Migrationen, Repositories, alle SQL-Anweisungen an einem Ort - packages/twitch: Secret-Speicher, OAuth, Helix mit Token-Bucket, IRC - apps/ingest: Daemon, Einrichtungsseite, Spike-Erkennung - 20 Tests (IRC-Parser, Spike-Detektor, Datenbankschicht) Der Chat verbindet sich anonym, solange nichts hinterlegt ist - damit laesst sich die Datenaufnahme pruefen, bevor die Twitch-Apps existieren. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013VTGjd92LsDDWF3frd9FTB
This commit is contained in:
1 parent
4ceb61f095
commit
d07c18441b
82 files changed
+2775
-838
No files matched your search
@@ -0,0 +1,122 @@
|
||||
// Minimaler YAML-Leser fuer unsere eigenen Konfigurationsdateien.
|
||||
//
|
||||
// Deckt genau das ab, was config/*.yaml benutzt: verschachtelte Maps ueber
|
||||
// Einrueckung, Skalare, Inline-Maps `{a: 1, b: 2}`, Listen aus Skalaren und
|
||||
// Blockskalare (`>` / `|`). Bewusst kein vollstaendiges YAML - das Projekt
|
||||
// kommt ohne npm-Abhaengigkeiten aus, und der Sprachumfang, den wir selbst
|
||||
// schreiben, ist ueberschaubar.
|
||||
|
||||
export type YamlValue = string | number | boolean | null | YamlValue[] | { [k: string]: YamlValue };
|
||||
export type YamlMap = { [k: string]: YamlValue };
|
||||
|
||||
function scalar(raw: string): YamlValue {
|
||||
const s = raw.trim();
|
||||
if (s === '' || s === '~' || s === 'null') return null;
|
||||
if (s === 'true') return true;
|
||||
if (s === 'false') return false;
|
||||
if (/^-?\d+$/.test(s)) return Number.parseInt(s, 10);
|
||||
if (/^-?\d*\.\d+$/.test(s)) return Number.parseFloat(s);
|
||||
if ((s.startsWith('"') && s.endsWith('"')) || (s.startsWith("'") && s.endsWith("'"))) {
|
||||
return s.slice(1, -1);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
function flowMap(raw: string): YamlMap {
|
||||
const out: YamlMap = {};
|
||||
for (const part of raw.slice(1, -1).split(',')) {
|
||||
if (!part.trim()) continue;
|
||||
const i = part.indexOf(':');
|
||||
if (i === -1) continue;
|
||||
out[part.slice(0, i).trim()] = scalar(part.slice(i + 1));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
function stripComment(line: string): string {
|
||||
let quote: string | null = null;
|
||||
for (let i = 0; i < line.length; i++) {
|
||||
const c = line[i]!;
|
||||
if (quote) {
|
||||
if (c === quote) quote = null;
|
||||
} else if (c === '"' || c === "'") {
|
||||
quote = c;
|
||||
} else if (c === '#' && (i === 0 || /\s/.test(line[i - 1]!))) {
|
||||
return line.slice(0, i);
|
||||
}
|
||||
}
|
||||
return line;
|
||||
}
|
||||
|
||||
type Frame = { indent: number; target: YamlMap; listKey?: string };
|
||||
|
||||
export function parseYaml(text: string): YamlMap {
|
||||
const lines = text.split(/\r?\n/);
|
||||
const root: YamlMap = {};
|
||||
const stack: Frame[] = [{ indent: -1, target: root }];
|
||||
let i = 0;
|
||||
|
||||
while (i < lines.length) {
|
||||
const line = stripComment(lines[i]!);
|
||||
if (!line.trim()) { i++; continue; }
|
||||
|
||||
const indent = line.length - line.trimStart().length;
|
||||
const body = line.trim();
|
||||
|
||||
while (stack.length > 1 && indent <= stack[stack.length - 1]!.indent) stack.pop();
|
||||
const frame = stack[stack.length - 1]!;
|
||||
|
||||
if (body.startsWith('- ')) {
|
||||
const key = frame.listKey;
|
||||
const list = key ? frame.target[key] : undefined;
|
||||
if (Array.isArray(list)) list.push(scalar(body.slice(2)));
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
const colon = body.indexOf(':');
|
||||
if (colon === -1) { i++; continue; }
|
||||
const key = body.slice(0, colon).trim();
|
||||
const rest = body.slice(colon + 1).trim();
|
||||
|
||||
if (rest === '') {
|
||||
// Verschachtelte Map, Liste oder leerer Wert - die naechste
|
||||
// inhaltstragende Zeile entscheidet
|
||||
let j = i + 1;
|
||||
while (j < lines.length && !stripComment(lines[j]!).trim()) j++;
|
||||
const next = j < lines.length ? stripComment(lines[j]!) : '';
|
||||
const nextIndent = next ? next.length - next.trimStart().length : -1;
|
||||
if (next && nextIndent > indent && next.trim().startsWith('- ')) {
|
||||
frame.target[key] = [];
|
||||
stack.push({ indent, target: frame.target, listKey: key });
|
||||
} else if (next && nextIndent > indent) {
|
||||
const child: YamlMap = {};
|
||||
frame.target[key] = child;
|
||||
stack.push({ indent, target: child });
|
||||
} else {
|
||||
frame.target[key] = null;
|
||||
}
|
||||
} else if (rest === '>' || rest === '|' || rest === '>-' || rest === '|-') {
|
||||
const parts: string[] = [];
|
||||
let j = i + 1;
|
||||
for (; j < lines.length; j++) {
|
||||
const raw = lines[j]!;
|
||||
if (!raw.trim()) { parts.push(''); continue; }
|
||||
if (raw.length - raw.trimStart().length <= indent) break;
|
||||
parts.push(raw.trim());
|
||||
}
|
||||
frame.target[key] = rest.startsWith('>') ? parts.join(' ').trim() : parts.join('\n');
|
||||
i = j;
|
||||
continue;
|
||||
} else if (rest.startsWith('{')) {
|
||||
frame.target[key] = flowMap(rest);
|
||||
} else if (rest.startsWith('[')) {
|
||||
frame.target[key] = rest.slice(1, -1).split(',').map(scalar).filter((v) => v !== null);
|
||||
} else {
|
||||
frame.target[key] = scalar(rest);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
return root;
|
||||
}
|
||||
Reference in new issue
Block a user