source: Klonkt/src/services/SettingsService.js@ e7f6691

main
Last change on this file since e7f6691 was 283f618, checked in by Robin Genis <roboburr@…>, 3 months ago

feat(fediverse): add an ActivityPub on/off toggle (off = no federation, no comments)

A solo site can now run without the fediverse. ap_enabled (default on, Beheer ->
Instellingen). When off: /ap/*, WebFinger and NodeInfo 404 (undiscoverable), the
'from the fediverse' reactions section is hidden on posts (= no comments, since
native comments were removed), the profile follow button and the fediverse admin
links disappear. Cirkels is separate (not gated here).

Co-Authored-By: Claude <noreply@…>

  • Property mode set to 100644
File size: 1.9 KB
Line 
1// Global app settings (key/value, cached). Primarily used for the tenancy mode.
2//
3// tenancy = 'solo' -> exactly one site (the primary/owner site)
4// tenancy = 'circle' -> solo site that federates with other solo Klonkt sites
5//
6// HUB MODE IS REMOVED (2026-06-24): multi-artist-per-domain was dropped in favour
7// of solo + Cirkels. getTenancy() coerces any legacy 'hub' value to 'solo' so all
8// the old `tenancy === 'hub'` branches are unreachable; the hub code is being
9// deleted incrementally.
10//
11// The cache is updated immediately on setSetting, so a toggle in admin
12// takes effect live without a restart.
13
14import db from '../config/database.js';
15
16let _cache = null;
17
18function load() {
19 if (!_cache) {
20 _cache = {};
21 for (const r of db.prepare('SELECT key, value FROM app_settings').all()) {
22 _cache[r.key] = r.value;
23 }
24 }
25 return _cache;
26}
27
28export function getSetting(key, fallback = null) {
29 const v = load()[key];
30 return v === undefined ? fallback : v;
31}
32
33export function setSetting(key, value) {
34 db.prepare(`
35 INSERT INTO app_settings (key, value, updated_at) VALUES (?, ?, CURRENT_TIMESTAMP)
36 ON CONFLICT(key) DO UPDATE SET value = excluded.value, updated_at = CURRENT_TIMESTAMP
37 `).run(key, String(value));
38 if (_cache) _cache[key] = String(value);
39}
40
41export function getTenancy() {
42 const v = getSetting('tenancy', 'solo');
43 // 'hub' is removed → coerce legacy values to 'solo'.
44 return v === 'circle' ? 'circle' : 'solo';
45}
46
47export function setTenancy(mode) {
48 const m = mode === 'circle' ? 'circle' : 'solo';
49 setSetting('tenancy', m);
50}
51
52// ActivityPub / fediverse federation. ON by default. '0' = off: the site does
53// not federate, /ap/* is gone, and the "from the fediverse" reactions disappear
54// — which (since native comments were removed) means no comments at all.
55export function apEnabled() {
56 return getSetting('ap_enabled', '1') !== '0';
57}
Note: See TracBrowser for help on using the repository browser.