mirror of
https://github.com/sussy-code/smov.git
synced 2024-12-29 16:07:40 +01:00
Report captcha solves
This commit is contained in:
parent
66001a16bc
commit
82d2516951
2 changed files with 21 additions and 3 deletions
|
@ -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(() => {});
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in a new issue