mirror of
https://github.com/movie-web/movie-web.git
synced 2025-01-12 23:19:09 +01:00
Report captcha solves
This commit is contained in:
parent
66001a16bc
commit
82d2516951
@ -9,6 +9,7 @@ import { PlayerMeta } from "@/stores/player/slices/source";
|
|||||||
// for anybody who cares - these are anonymous metrics.
|
// for anybody who cares - these are anonymous metrics.
|
||||||
// They are just used for figuring out if providers are broken or not
|
// They are just used for figuring out if providers are broken or not
|
||||||
const metricsEndpoint = "https://backend.movie-web.app/metrics/providers";
|
const metricsEndpoint = "https://backend.movie-web.app/metrics/providers";
|
||||||
|
const captchaMetricsEndpoint = "https://backend.movie-web.app/metrics/captcha";
|
||||||
const batchId = () => nanoid(32);
|
const batchId = () => nanoid(32);
|
||||||
|
|
||||||
export type ProviderMetric = {
|
export type ProviderMetric = {
|
||||||
@ -136,8 +137,17 @@ export function scrapePartsToProviderMetric(
|
|||||||
export function useReportProviders() {
|
export function useReportProviders() {
|
||||||
const report = useCallback((items: ProviderMetric[]) => {
|
const report = useCallback((items: ProviderMetric[]) => {
|
||||||
if (items.length === 0) return;
|
if (items.length === 0) return;
|
||||||
reportProviders(items);
|
reportProviders(items).catch(() => {});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return { report };
|
return { report };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function reportCaptchaSolve(success: boolean) {
|
||||||
|
ofetch(captchaMetricsEndpoint, {
|
||||||
|
method: "POST",
|
||||||
|
body: {
|
||||||
|
success,
|
||||||
|
},
|
||||||
|
}).catch(() => {});
|
||||||
|
}
|
||||||
|
@ -2,6 +2,7 @@ import Turnstile, { BoundTurnstileObject } from "react-turnstile";
|
|||||||
import { create } from "zustand";
|
import { create } from "zustand";
|
||||||
import { immer } from "zustand/middleware/immer";
|
import { immer } from "zustand/middleware/immer";
|
||||||
|
|
||||||
|
import { reportCaptchaSolve } from "@/backend/helpers/report";
|
||||||
import { conf } from "@/setup/config";
|
import { conf } from "@/setup/config";
|
||||||
|
|
||||||
export interface TurnstileStore {
|
export interface TurnstileStore {
|
||||||
@ -52,11 +53,18 @@ export function isTurnstileInitialized() {
|
|||||||
return !!getTurnstile();
|
return !!getTurnstile();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getTurnstileToken() {
|
export async function getTurnstileToken() {
|
||||||
const turnstile = getTurnstile();
|
const turnstile = getTurnstile();
|
||||||
turnstile?.reset();
|
turnstile?.reset();
|
||||||
turnstile?.execute();
|
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() {
|
export function TurnstileProvider() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user