diff --git a/src/backend/helpers/report.ts b/src/backend/helpers/report.ts index b7c32645..1150c22d 100644 --- a/src/backend/helpers/report.ts +++ b/src/backend/helpers/report.ts @@ -9,6 +9,7 @@ import { PlayerMeta } from "@/stores/player/slices/source"; // for anybody who cares - these are anonymous metrics. // They are just used for figuring out if providers are broken or not const metricsEndpoint = "https://backend.movie-web.app/metrics/providers"; +const captchaMetricsEndpoint = "https://backend.movie-web.app/metrics/captcha"; const batchId = () => nanoid(32); export type ProviderMetric = { @@ -136,8 +137,17 @@ export function scrapePartsToProviderMetric( export function useReportProviders() { const report = useCallback((items: ProviderMetric[]) => { if (items.length === 0) return; - reportProviders(items); + reportProviders(items).catch(() => {}); }, []); return { report }; } + +export function reportCaptchaSolve(success: boolean) { + ofetch(captchaMetricsEndpoint, { + method: "POST", + body: { + success, + }, + }).catch(() => {}); +} diff --git a/src/stores/turnstile/index.tsx b/src/stores/turnstile/index.tsx index 907ffc2e..0d7727f6 100644 --- a/src/stores/turnstile/index.tsx +++ b/src/stores/turnstile/index.tsx @@ -2,6 +2,7 @@ import Turnstile, { BoundTurnstileObject } from "react-turnstile"; import { create } from "zustand"; import { immer } from "zustand/middleware/immer"; +import { reportCaptchaSolve } from "@/backend/helpers/report"; import { conf } from "@/setup/config"; export interface TurnstileStore { @@ -52,11 +53,18 @@ export function isTurnstileInitialized() { return !!getTurnstile(); } -export function getTurnstileToken() { +export async function getTurnstileToken() { const turnstile = getTurnstile(); turnstile?.reset(); turnstile?.execute(); - return useTurnstileStore.getState().getToken(); + try { + const token = await useTurnstileStore.getState().getToken(); + reportCaptchaSolve(true); + return token; + } catch (err) { + reportCaptchaSolve(false); + throw err; + } } export function TurnstileProvider() {