fix(admin): persist image quota by setting remaining directly

Use PUT setImageQuota so admins can lower remaining below the stored plan
limit; grant-only bonus updates silently no-op when bonus is already zero.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
john
2026-08-05 16:22:22 +08:00
parent eca1aa635e
commit d0183cb636
3 changed files with 51 additions and 22 deletions
+19
View File
@@ -1233,6 +1233,25 @@ export function createAdminApp(services) {
});
});
adminApi.put('/users/:userId/image-quota', requireAdmin, async (req, res) => {
if (!subscriptionService?.setImageQuota) {
return res.status(503).json({ message: '图片额度服务未启用' });
}
const remaining = req.body?.remaining;
const total = req.body?.total;
const note = String(req.body?.note ?? '').trim();
const result = await subscriptionService.setImageQuota(
req.params.userId,
{
remaining: remaining === undefined || remaining === null ? null : Math.floor(Number(remaining)),
total: total === undefined || total === null ? null : Math.floor(Number(total)),
},
{ operatorId: req.currentUser.id, note },
);
if (!result.ok) return res.status(400).json({ message: result.message });
res.json(result);
});
adminApi.post('/users/:userId/image-quota/grant', requireAdmin, async (req, res) => {
if (!subscriptionService?.grantImageQuota) {
return res.status(503).json({ message: '图片额度服务未启用' });