Session 20: Provider intelligence — quota tracker, gateway with fallback cascade, admin quota dashboard (1476 tests)
This commit is contained in:
@@ -17,11 +17,31 @@
|
||||
const express = require('express');
|
||||
const { requireInternalAuth } = require('../middleware/internalAuth');
|
||||
const tank01Prefetch = require('../../scripts/tank01-prefetch');
|
||||
const quotaTracker = require('../services/quotaTracker');
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
router.use(requireInternalAuth({ loopbackOnly: false }));
|
||||
|
||||
/**
|
||||
* GET /api/internal/quota (Session 20)
|
||||
*
|
||||
* Snapshot of every configured provider's current quota counter.
|
||||
* Consumed by the admin dashboard's "Provider Quotas" tile. Cached
|
||||
* for 5s so a refresh-button mash doesn't flood Redis.
|
||||
*/
|
||||
router.get('/quota', async (req, res) => {
|
||||
try {
|
||||
const providers = await quotaTracker.getAllQuotaStatuses();
|
||||
res.set('Cache-Control', 'private, max-age=5');
|
||||
return res.json({ ok: true, providers });
|
||||
} catch (err) {
|
||||
const message = err && err.message ? err.message : String(err);
|
||||
console.error('[internal/quota] failed:', message);
|
||||
return res.status(500).json({ ok: false, error: message });
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* POST /api/internal/prefetch/tank01
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user