| [834bcc3] | 1 | // Global app settings (key/value, cached). Primarily used for the tenancy mode.
|
|---|
| [6351545] | 2 | //
|
|---|
| [dd856db] | 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.
|
|---|
| [6351545] | 10 | //
|
|---|
| [834bcc3] | 11 | // The cache is updated immediately on setSetting, so a toggle in admin
|
|---|
| 12 | // takes effect live without a restart.
|
|---|
| [6351545] | 13 |
|
|---|
| 14 | import db from '../config/database.js';
|
|---|
| 15 |
|
|---|
| 16 | let _cache = null;
|
|---|
| 17 |
|
|---|
| 18 | function 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 |
|
|---|
| 28 | export function getSetting(key, fallback = null) {
|
|---|
| 29 | const v = load()[key];
|
|---|
| 30 | return v === undefined ? fallback : v;
|
|---|
| 31 | }
|
|---|
| 32 |
|
|---|
| 33 | export 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 |
|
|---|
| 41 | export function getTenancy() {
|
|---|
| [b300682] | 42 | const v = getSetting('tenancy', 'solo');
|
|---|
| [dd856db] | 43 | // 'hub' is removed → coerce legacy values to 'solo'.
|
|---|
| 44 | return v === 'circle' ? 'circle' : 'solo';
|
|---|
| [6351545] | 45 | }
|
|---|
| 46 |
|
|---|
| 47 | export function setTenancy(mode) {
|
|---|
| [dd856db] | 48 | const m = mode === 'circle' ? 'circle' : 'solo';
|
|---|
| [b300682] | 49 | setSetting('tenancy', m);
|
|---|
| [6351545] | 50 | }
|
|---|
| [283f618] | 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.
|
|---|
| 55 | export function apEnabled() {
|
|---|
| 56 | return getSetting('ap_enabled', '1') !== '0';
|
|---|
| 57 | }
|
|---|