pstream is dead; long live pstream taciturnaxolotl.github.io/pstream-ng/
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix metric reporting with multiple servers

Pas 0d4c6471 a019f3da

+18 -5
+18 -5
src/backend/helpers/report.ts
··· 5 5 6 6 import { isExtensionActiveCached } from "@/backend/extension/messaging"; 7 7 import { ScrapingItems, ScrapingSegment } from "@/hooks/useProviderScrape"; 8 - import { BACKEND_URL } from "@/setup/constants"; 8 + import { conf } from "@/setup/config"; 9 9 import { useAuthStore } from "@/stores/auth"; 10 10 import { PlayerMeta } from "@/stores/player/slices/source"; 11 11 12 12 // for anybody who cares - these are anonymous metrics. 13 13 // They are just used for figuring out if providers are broken or not 14 - const metricsEndpoint = `${BACKEND_URL}/metrics/providers`; 15 - const captchaMetricsEndpoint = `${BACKEND_URL}/metrics/captcha`; 14 + // Metrics are always sent to the first configured backend 15 + function getMetricsBackendUrl(): string | null { 16 + const config = conf(); 17 + return config.BACKEND_URLS.length > 0 18 + ? config.BACKEND_URLS[0] 19 + : config.BACKEND_URL; 20 + } 21 + 22 + function getMetricsEndpoint(path: string): string | null { 23 + const backendUrl = getMetricsBackendUrl(); 24 + return backendUrl ? `${backendUrl}${path}` : null; 25 + } 26 + 27 + const metricsEndpoint = getMetricsEndpoint("/metrics/providers"); 28 + const captchaMetricsEndpoint = getMetricsEndpoint("/metrics/captcha"); 16 29 const batchId = () => nanoid(32); 17 30 18 31 export type ProviderMetric = { ··· 45 58 } 46 59 47 60 export async function reportProviders(items: ProviderMetric[]): Promise<void> { 48 - if (!BACKEND_URL) return; 61 + if (!metricsEndpoint) return; 49 62 return ofetch(metricsEndpoint, { 50 63 method: "POST", 51 64 body: { ··· 158 171 } 159 172 160 173 export function reportCaptchaSolve(success: boolean) { 161 - if (!BACKEND_URL) return; 174 + if (!captchaMetricsEndpoint) return; 162 175 ofetch(captchaMetricsEndpoint, { 163 176 method: "POST", 164 177 body: {