mirror of
https://github.com/HeyPuter/puter.git
synced 2026-01-06 05:00:29 -06:00
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:
@@ -1,3 +1,7 @@
|
||||
{
|
||||
"unlimitedUsage": false
|
||||
"unlimitedUsage": false,
|
||||
"allowedGlobalUsageUsers": [
|
||||
"06ab2f87-aef5-441b-9c60-debbb8d24dda",
|
||||
"d8fd169b-4e93-484a-bd84-115b5a2f0ed4"
|
||||
]
|
||||
}
|
||||
@@ -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');
|
||||
Reference in New Issue
Block a user