mirror of
https://github.com/Routstr/routstrd.git
synced 2026-08-09 03:44:38 +00:00
refactor(usage): remove CLI-side suffix filtering now that auth proxy handles it
The auth proxy intercepts GET /usage and returns only entries belonging to the authenticated npub's clients, with owner suffixes stripped. The TUI no longer needs to filter entries client-side. - Remove getNpubSuffix and loadConfig from tui/usage/data.ts imports - Remove old suffix-based filtering logic from fetchUsage() - Remove unused getNpubSuffix from cli.ts imports
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
{
|
||||
"lockfileVersion": 0,
|
||||
"lockfileVersion": 1,
|
||||
"configVersion": 0,
|
||||
"workspaces": {
|
||||
"": {
|
||||
"dependencies": {
|
||||
@@ -8,6 +9,7 @@
|
||||
"applesauce-core": "^5.1.0",
|
||||
"applesauce-relay": "^5.1.0",
|
||||
"commander": "^14.0.2",
|
||||
"nostr-tools": "^2.12.0",
|
||||
"qrcode": "^1.5.4",
|
||||
"rxjs": "^7.8.1",
|
||||
"zustand": "^5.0.5",
|
||||
|
||||
@@ -7,7 +7,6 @@ import {
|
||||
isDaemonRunning,
|
||||
loadConfig,
|
||||
getDaemonBaseUrl,
|
||||
getNpubSuffix,
|
||||
getUserNpub,
|
||||
} from "./utils/daemon-client";
|
||||
import {
|
||||
|
||||
+4
-15
@@ -1,5 +1,5 @@
|
||||
import type { UsageTrackingEntry } from "../../daemon/types.ts";
|
||||
import { callDaemon, getNpubSuffix, isDaemonRunning, loadConfig } from "../../utils/daemon-client.ts";
|
||||
import { callDaemon, isDaemonRunning } from "../../utils/daemon-client.ts";
|
||||
import type { ClientStats, DayStats, ModelStats, ProviderStats, UsageStats } from "./types.ts";
|
||||
|
||||
export interface BalanceKey {
|
||||
@@ -82,21 +82,10 @@ export async function fetchUsage(limit = 10000): Promise<UsageStats | null> {
|
||||
const result = await callDaemon(`/usage?limit=${limit}`);
|
||||
if (result.error) return null;
|
||||
|
||||
// The daemon returns { output: [...] } where output is the entries array directly.
|
||||
// In remote daemon mode, client IDs are suffixed with the last 7 chars of our npub.
|
||||
// Fetch the full daemon result, but only display/aggregate entries for our clients.
|
||||
// The auth proxy filters usage to the authenticated npub's clients and
|
||||
// returns client IDs without the owner suffix.
|
||||
const entries = result.output as UsageTrackingEntry[] | undefined;
|
||||
const entriesArray = Array.isArray(entries) ? entries : [];
|
||||
const suffix = getNpubSuffix(await loadConfig());
|
||||
const suffixStr = suffix ? `-${suffix}` : null;
|
||||
const visibleEntries = suffixStr
|
||||
? entriesArray
|
||||
.filter((entry) => entry.client?.endsWith(suffixStr))
|
||||
.map((entry) => ({
|
||||
...entry,
|
||||
client: entry.client?.slice(0, -suffixStr.length),
|
||||
}))
|
||||
: entriesArray;
|
||||
const visibleEntries = Array.isArray(entries) ? entries : [];
|
||||
|
||||
// Calculate totals from visible entries
|
||||
const totals = visibleEntries.reduce(
|
||||
|
||||
Reference in New Issue
Block a user