mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-01 17:03:15 +00:00
refactor(server): remaining nest domains read env via app-config
This commit is contained in:
@@ -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.');
|
||||
}
|
||||
|
||||
@@ -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. */
|
||||
|
||||
Reference in New Issue
Block a user