ive choped chopped it

This commit is contained in:
mrjvs 2023-11-10 22:14:41 +01:00
parent 6978314fdb
commit a7bd4786f3
2 changed files with 62 additions and 1 deletions

View 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 };
}

View file

@ -3,6 +3,10 @@ import classNames from "classnames";
import { useEffect, useRef } from "react";
import type { AsyncReturnType } from "type-fest";
import {
scrapSegmentToProviderMetric,
useReportProviders,
} from "@/backend/helpers/report";
import { usePlayer } from "@/components/player/hooks/usePlayer";
import {
ScrapeCard,
@ -26,6 +30,7 @@ export interface ScrapingProps {
export function ScrapingPart(props: ScrapingProps) {
const { playMedia } = usePlayer();
const { report } = useReportProviders();
const { startScraping, sourceOrder, sources, currentSource } = useScrape();
const containerRef = useRef<HTMLDivElement | null>(null);
@ -58,9 +63,14 @@ export function ScrapingPart(props: ScrapingProps) {
resultRef.current.sources,
resultRef.current.sourceOrder
);
report(
Object.values(resultRef.current.sources).map((v) =>
scrapSegmentToProviderMetric(v)
)
);
props.onGetStream?.(output);
})();
}, [startScraping, props, playMedia]);
}, [startScraping, props, playMedia, report]);
const currentProvider = sourceOrder.find(
(s) => sources[s.id].status === "pending"