mirror of
https://github.com/movie-web/movie-web.git
synced 2024-11-11 04:35:09 +01:00
ive choped chopped it
This commit is contained in:
parent
6978314fdb
commit
a7bd4786f3
51
src/backend/helpers/report.ts
Normal file
51
src/backend/helpers/report.ts
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
import { ofetch } from "ofetch";
|
||||||
|
import { useCallback } from "react";
|
||||||
|
|
||||||
|
import { useBackendUrl } from "@/hooks/auth/useBackendUrl";
|
||||||
|
import { ScrapingSegment } from "@/hooks/useProviderScrape";
|
||||||
|
|
||||||
|
export type ProviderMetric = {
|
||||||
|
tmdbId: string;
|
||||||
|
type: string;
|
||||||
|
title: string;
|
||||||
|
seasonId?: string;
|
||||||
|
episodeId?: string;
|
||||||
|
status: "failed" | "notfound" | "success";
|
||||||
|
providerId: string;
|
||||||
|
embedId?: string;
|
||||||
|
errorMessage?: string;
|
||||||
|
fullError?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export async function reportProviders(
|
||||||
|
url: string,
|
||||||
|
items: ProviderMetric[]
|
||||||
|
): Promise<void> {
|
||||||
|
return ofetch("/metrics/providers", {
|
||||||
|
method: "POST",
|
||||||
|
body: {
|
||||||
|
items,
|
||||||
|
},
|
||||||
|
baseURL: url,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function scrapSegmentToProviderMetric(
|
||||||
|
_segment: ScrapingSegment
|
||||||
|
): ProviderMetric {
|
||||||
|
// TODO actually convert this
|
||||||
|
return {} as any;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useReportProviders() {
|
||||||
|
const url = useBackendUrl();
|
||||||
|
// TODO constant url
|
||||||
|
const report = useCallback(
|
||||||
|
(items: ProviderMetric[]) => {
|
||||||
|
reportProviders(url, items);
|
||||||
|
},
|
||||||
|
[url]
|
||||||
|
);
|
||||||
|
|
||||||
|
return { report };
|
||||||
|
}
|
@ -3,6 +3,10 @@ import classNames from "classnames";
|
|||||||
import { useEffect, useRef } from "react";
|
import { useEffect, useRef } from "react";
|
||||||
import type { AsyncReturnType } from "type-fest";
|
import type { AsyncReturnType } from "type-fest";
|
||||||
|
|
||||||
|
import {
|
||||||
|
scrapSegmentToProviderMetric,
|
||||||
|
useReportProviders,
|
||||||
|
} from "@/backend/helpers/report";
|
||||||
import { usePlayer } from "@/components/player/hooks/usePlayer";
|
import { usePlayer } from "@/components/player/hooks/usePlayer";
|
||||||
import {
|
import {
|
||||||
ScrapeCard,
|
ScrapeCard,
|
||||||
@ -26,6 +30,7 @@ export interface ScrapingProps {
|
|||||||
|
|
||||||
export function ScrapingPart(props: ScrapingProps) {
|
export function ScrapingPart(props: ScrapingProps) {
|
||||||
const { playMedia } = usePlayer();
|
const { playMedia } = usePlayer();
|
||||||
|
const { report } = useReportProviders();
|
||||||
const { startScraping, sourceOrder, sources, currentSource } = useScrape();
|
const { startScraping, sourceOrder, sources, currentSource } = useScrape();
|
||||||
|
|
||||||
const containerRef = useRef<HTMLDivElement | null>(null);
|
const containerRef = useRef<HTMLDivElement | null>(null);
|
||||||
@ -58,9 +63,14 @@ export function ScrapingPart(props: ScrapingProps) {
|
|||||||
resultRef.current.sources,
|
resultRef.current.sources,
|
||||||
resultRef.current.sourceOrder
|
resultRef.current.sourceOrder
|
||||||
);
|
);
|
||||||
|
report(
|
||||||
|
Object.values(resultRef.current.sources).map((v) =>
|
||||||
|
scrapSegmentToProviderMetric(v)
|
||||||
|
)
|
||||||
|
);
|
||||||
props.onGetStream?.(output);
|
props.onGetStream?.(output);
|
||||||
})();
|
})();
|
||||||
}, [startScraping, props, playMedia]);
|
}, [startScraping, props, playMedia, report]);
|
||||||
|
|
||||||
const currentProvider = sourceOrder.find(
|
const currentProvider = sourceOrder.find(
|
||||||
(s) => sources[s.id].status === "pending"
|
(s) => sources[s.id].status === "pending"
|
||||||
|
Loading…
Reference in New Issue
Block a user