addeed npub filtering for /usage as well

This commit is contained in:
redshift
2026-06-11 09:31:32 +08:00
parent 61acc0b5fb
commit 8c52c90f94
+8
View File
@@ -1125,8 +1125,16 @@ export function createDaemonRequestHandler(deps: {
if (req.method === "GET" && url.pathname === "/usage") {
try {
const npubFilter = url.searchParams.get("npub")?.trim();
const clients = npubFilter ? getClientsFromStore(deps.store) : undefined;
const clientFilter = npubFilter
? clients!
.filter((c) => c.ownerNpub === npubFilter)
.map((c) => c.clientId)
: undefined;
const output = await deps.usageTrackingDriver.list({
limit: parseLimit(url.searchParams.get("limit")),
...(clientFilter ? { clients: clientFilter } : {}),
});
res.writeHead(200, { "Content-Type": "application/json" });
res.end(JSON.stringify({ output }));