mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-18 14:08:21 +00:00
* 🗓️ feat: Align Balance Resets to Fixed Calendar Boundaries Add balance.refillAnchor, an ISO timestamp with a fixed offset that periods align to: a refill or reset is due at the first anchor-plus-whole-intervals boundary after the last one, so every user resets at the same moment (e.g. each Monday at 00:00 UTC, or the 1st of each month). Omitted, periods keep running from each user's last refill. The gauge names the reset date for anchored periods. * 🧭 fix: Clear a Removed Reset Anchor During Admission and Shape Balance Responses in TS A policy built without a record now always carries refillAnchor, null when unset, so removing the setting clears a stored anchor instead of looping admission until its retry bound throws. Balance response shaping moves to toBalanceResponse in packages/api; the CJS controller delegates to it.
20 lines
567 B
JavaScript
20 lines
567 B
JavaScript
const { toBalanceResponse } = require('@librechat/api');
|
|
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' });
|
|
}
|
|
|
|
res.status(200).json(toBalanceResponse(balanceData));
|
|
}
|
|
|
|
module.exports = balanceController;
|