feat: route for global usage aggregate (#1810)

* feat: route for global usage aggregate

* feat: add globalUsageEndpoint to puter-js

* fix: globalUsage endpoint
This commit is contained in:
Daniel Salazar
2025-10-22 16:46:13 -07:00
committed by GitHub
parent c9ab01cf1e
commit 256189a7de
6 changed files with 123 additions and 18 deletions

View File

@@ -1,3 +1,7 @@
{
"unlimitedUsage": false
"unlimitedUsage": false,
"allowedGlobalUsageUsers": [
"06ab2f87-aef5-441b-9c60-debbb8d24dda",
"d8fd169b-4e93-484a-bd84-115b5a2f0ed4"
]
}

View File

@@ -35,4 +35,23 @@ extension.get('/metering/usage/:appId', { subdomain: 'api' }, async (req, res) =
return;
});
extension.get('/metering/globalUsage', { subdomain: 'api' }, async (req, res) => {
const meteringService = meteringServiceWrapper.meteringService;
const actor = req.actor;
if ( !actor ) {
throw Error('actor not found in context');
}
// check if actor is allowed to view global usage
const allowedUsers = extension.config.allowedGlobalUsageUsers || [];
if ( !allowedUsers.includes(actor.type?.user.uuid) ) {
res.status(403).json({ error: 'You are not authorized to view global usage' });
return;
}
const globalUsage = await meteringService.getGlobalUsage();
res.status(200).json(globalUsage);
return;
});
console.debug('Loaded /metering/usage route');