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

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

Branding: 100% PrutCMS/PrutFolio-free — Klonkt as original product

All fork/lineage references (README, package description, server/comments,
PrutFolio-as-noun -> Klonkt-site) removed. Plus a small, mysterious wink
at a certain Bart in CircleFederation.js. Internal package name (prutfolio)
+ PWA id + server paths left untouched (stability).

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 Klonkt-site'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.