mirror of
https://github.com/sussy-code/smov.git
synced 2024-12-29 16:07:40 +01:00
Abortable scraping
Co-authored-by: mrjvs <mistrjvs@gmail.com>
This commit is contained in:
parent
95c5e73996
commit
ca0ccb240e
1 changed files with 4 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
|||
import { ProviderControls, ScrapeMedia } from "@movie-web/providers";
|
||||
import classNames from "classnames";
|
||||
import { useEffect, useRef } from "react";
|
||||
import { useMountedState } from "react-use";
|
||||
import type { AsyncReturnType } from "type-fest";
|
||||
|
||||
import {
|
||||
|
@ -30,6 +31,7 @@ export interface ScrapingProps {
|
|||
export function ScrapingPart(props: ScrapingProps) {
|
||||
const { report } = useReportProviders();
|
||||
const { startScraping, sourceOrder, sources, currentSource } = useScrape();
|
||||
const isMounted = useMountedState();
|
||||
|
||||
const containerRef = useRef<HTMLDivElement | null>(null);
|
||||
const listRef = useRef<HTMLDivElement | null>(null);
|
||||
|
@ -57,6 +59,7 @@ export function ScrapingPart(props: ScrapingProps) {
|
|||
started.current = true;
|
||||
(async () => {
|
||||
const output = await startScraping(props.media);
|
||||
if (!isMounted()) return;
|
||||
props.onResult?.(
|
||||
resultRef.current.sources,
|
||||
resultRef.current.sourceOrder
|
||||
|
@ -70,7 +73,7 @@ export function ScrapingPart(props: ScrapingProps) {
|
|||
);
|
||||
props.onGetStream?.(output);
|
||||
})();
|
||||
}, [startScraping, props, report]);
|
||||
}, [startScraping, props, report, isMounted]);
|
||||
|
||||
const currentProvider = sourceOrder.find(
|
||||
(s) => sources[s.id].status === "pending"
|
||||
|
|
Loading…
Reference in a new issue