mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-06-09 17:31:19 +00:00
* chore: reduce auth and balance operational noise * chore: tighten balance and capability noise handling * chore: avoid balance 404s when disabled * chore: use response locals for balance handoff
28 lines
711 B
JavaScript
28 lines
711 B
JavaScript
const { findBalanceByUser } = require('~/models');
|
|
|
|
async function balanceController(req, res) {
|
|
const balanceLocals = res.locals || {};
|
|
|
|
if (balanceLocals.balanceConfigEnabled === false) {
|
|
return res.sendStatus(204);
|
|
}
|
|
|
|
const balanceData = balanceLocals.balanceData ?? (await findBalanceByUser(req.user.id));
|
|
|
|
if (!balanceData) {
|
|
return res.status(404).json({ error: 'Balance not found' });
|
|
}
|
|
|
|
const { _id: _, ...result } = balanceData;
|
|
|
|
if (!result.autoRefillEnabled) {
|
|
delete result.refillIntervalValue;
|
|
delete result.refillIntervalUnit;
|
|
delete result.lastRefill;
|
|
delete result.refillAmount;
|
|
}
|
|
|
|
res.status(200).json(result);
|
|
}
|
|
|
|
module.exports = balanceController;
|