refactor(server): remaining nest domains read env via app-config

This commit is contained in:
jubnl
2026-07-25 15:29:13 +02:00
parent 9e87e09d03
commit d13758221e
15 changed files with 49 additions and 29 deletions
@@ -1,3 +1,4 @@
import { readEnv } from '../../../app-config';
import { db, canAccessTrip } from '../../../db/database';
import { broadcast, broadcastToUser } from '../../../websocket';
import { listBudgetItems } from '../../../services/budgetService';
@@ -279,7 +280,7 @@ export function createRealRpcHost(id: string, granted: ReadonlySet<string>, rout
// bytes to the shared demo instance, even through a plugin's db:write:files.
// Only resolve the email when demo mode is actually on — keeps the hot path
// (and the schema surface) untouched for self-hosted installs.
if (process.env.DEMO_MODE?.toLowerCase() === 'true') {
if (readEnv().demo.enabled) {
const uploader = db.prepare('SELECT email FROM users WHERE id = ?').get(actingUserId) as { email?: string } | undefined;
if (isDemoEmail(uploader?.email)) throw new ForbiddenResource('Uploads are disabled in demo mode.');
}
+8 -5
View File
@@ -11,6 +11,7 @@
*
* Pure + dependency-free (a clock is injected) so it unit-tests without timers.
*/
import { readEnv } from '../../../app-config';
/** A refilling token bucket: `capacity` tokens, refilled at `refillPerSec`. */
export class TokenBucket {
@@ -51,10 +52,12 @@ export interface RpcLimitConfig {
// Generous defaults: a legitimate plugin handling a request makes a handful of ctx
// calls; these only bite a runaway loop. Overridable via env for tuning.
// Frozen at import on purpose (legacy timing) — the limits are boot-stable.
const pluginTuning = readEnv().plugins;
export const DEFAULT_RPC_LIMIT: RpcLimitConfig = {
burst: Number(process.env.TREK_PLUGIN_RPC_BURST) || 60,
perSec: Number(process.env.TREK_PLUGIN_RPC_PER_SEC) || 20,
maxInFlight: Number(process.env.TREK_PLUGIN_RPC_INFLIGHT) || 16,
burst: pluginTuning.rpcBurst,
perSec: pluginTuning.rpcPerSec,
maxInFlight: pluginTuning.rpcInflight,
};
// Plugin log volume (ctx.log.*, stdout/stderr, unknown evt topics) reaches the
@@ -63,8 +66,8 @@ export const DEFAULT_RPC_LIMIT: RpcLimitConfig = {
// `while (true) ctx.log.error(...)` loop can't pin the host thread; a legitimate
// plugin logs far below this and never notices. Excess lines are dropped.
export const DEFAULT_LOG_LIMIT = {
burst: Number(process.env.TREK_PLUGIN_LOG_BURST) || 50,
perSec: Number(process.env.TREK_PLUGIN_LOG_PER_SEC) || 10,
burst: pluginTuning.logBurst,
perSec: pluginTuning.logPerSec,
};
/** Per-plugin limiter: a token bucket + an in-flight gauge. */