Forum teuk.org

mbweb β€” Refactoring and fixes round 2 (April 2026)

in Mediabot Β· started by TeuK Β· yesterday

TeuK Β· yesterday

mbweb β€” Refactoring and fixes round 2 (April 2026)

Context

Follow-up on the first audit pass. This article covers the six improvements and refactors applied after the initial bug fixes.


Changes

G β€” Dead code removed from viewHelpers.js

yesNo() and isEnabled() were exported but never imported anywhere in the codebase. Both functions were removed. boolLabel() remains as the single utility for boolean display.


R10 β€” fmtUptime moved to viewHelpers.js

fmtUptime() was defined inline inside the GET / request handler, meaning it was re-created on every request. It is now a named export in lib/viewHelpers.js and imported at module level in app.js.


H β€” Quotes, Commands and Network added to navigation

lib/render.js only included Profil, Channels and Radio in the nav bar. Quotes and Commands are now visible to all authenticated users. Network and Users are conditionally shown to Master and above.


E β€” findMount was matching against server_name instead of serverName

In lib/radio.js, findMount() is called with the normalized mounts array where raw Icecast fields have been camel-cased. The fallback .find() was still checking src.server_name (always undefined on normalized objects) instead of src.serverName. The mount lookup now works correctly across all fallback paths.


R11 β€” Duplicate level calculation removed from mediabotRepository.js

userHasChannelAccess() was computing the semantic user level inline, duplicating the logic already in globalLevel() from permissions.js. The function now imports and calls globalLevel() directly β€” single source of truth for level resolution across the codebase.


R13 β€” express-rate-limit removed from package.json

The package was listed under optionalDependencies but was never imported or used. Rate limiting on the login route is handled by a lightweight custom implementation in routes/auth.js. The dead dependency entry has been removed.


Status

# Item Status
G Dead code yesNo/isEnabled βœ… removed
R10 fmtUptime inline β†’ viewHelpers.js βœ… done
H Nav: Quotes / Commands / Network βœ… added
E findMount server_name β†’ serverName βœ… fixed
R11 Duplicate level calc in repository βœ… removed
R13 Dead express-rate-limit dep βœ… removed

Next: split app.js into dedicated route files and extract Prometheus helpers into lib/metrics.js (R9).

You must be logged in to reply.