source: Klonkt/src/services/SettingsService.js@ 57929aa

main
Last change on this file since 57929aa was b300682, checked in by roboburr <roboburr@…>, 3 months ago

Circles v1 — foundation: migration + signed own publication

Steps 1+2 of the Circles federation (3rd tenancy mode alongside solo/hub):

  • DB: circle_links / remote_actors / remote_posts (idempotent in initializeDatabase)
  • SettingsService: tenancy now accepts 'circle'
  • CircleFederation.js: per-instance Ed25519 keypair (app_settings) + actor/outbox builders + sign/verify (SPKI-DER pubkey, signature over raw body)
  • routes/federation.js: GET /.klonkt/actor.json + signed /.klonkt/outbox.json, mounted in server.js before resolveSite
  • docs/cirkels-v1-spec.md: full v1 spec

Still to do: CircleService.sync (pull+verify), Admin UI, /cirkel feed, hardening.
Ed25519 sign/verify round-trip verified in isolation; syntax clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@…>

  • Property mode set to 100644
File size: 1.3 KB
Line 
1// Globale app-instellingen (key/value, gecached). Nu vooral de tenancy-modus.
2//
3// tenancy = 'solo' -> precies één site (de primaire/owner-site)
4// tenancy = 'hub' -> hoofdsite (bedrijf) + /user/, admin wijst PrutFolio's toe
5//
6// De cache wordt bij setSetting meteen ververst, dus een toggle in Beheer werkt
7// live zonder herstart.
8
9import db from '../config/database.js';
10
11let _cache = null;
12
13function load() {
14 if (!_cache) {
15 _cache = {};
16 for (const r of db.prepare('SELECT key, value FROM app_settings').all()) {
17 _cache[r.key] = r.value;
18 }
19 }
20 return _cache;
21}
22
23export function getSetting(key, fallback = null) {
24 const v = load()[key];
25 return v === undefined ? fallback : v;
26}
27
28export function setSetting(key, value) {
29 db.prepare(`
30 INSERT INTO app_settings (key, value, updated_at) VALUES (?, ?, CURRENT_TIMESTAMP)
31 ON CONFLICT(key) DO UPDATE SET value = excluded.value, updated_at = CURRENT_TIMESTAMP
32 `).run(key, String(value));
33 if (_cache) _cache[key] = String(value);
34}
35
36export function getTenancy() {
37 const v = getSetting('tenancy', 'solo');
38 return v === 'hub' ? 'hub' : v === 'circle' ? 'circle' : 'solo';
39}
40
41export function setTenancy(mode) {
42 const m = (mode === 'hub' || mode === 'circle') ? mode : 'solo';
43 setSetting('tenancy', m);
44}
Note: See TracBrowser for help on using the repository browser.