source: Klonkt/src/services/SettingsService.js@ 7c44c12

main
Last change on this file since 7c44c12 was 834bcc3, checked in by Robin Genis <roboburr@…>, 3 months ago

i18n: translate Dutch code comments to English across src/

Comments in routes/services/views/config/middleware/assets translated to
English for the public repo. A few dev-facing throw/console message strings
were Englished too. No user-facing UI strings or i18n dictionary values changed
(src/services/i18n.js untouched). Logic unchanged.

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

  • Property mode set to 100644
File size: 1.3 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 = 'hub' -> main site (company) + /user/, admin assigns Klonkt sites
5//
6// The cache is updated immediately on setSetting, so a toggle in admin
7// takes effect live without a restart.
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.