mirror of
https://github.com/movie-web/native-app.git
synced 2025-09-13 16:03:26 +00:00
feat: event types and better loading log
This commit is contained in:
@@ -2,6 +2,7 @@ import { useEffect, useState } from "react";
|
|||||||
import { Text } from "react-native";
|
import { Text } from "react-native";
|
||||||
import { useLocalSearchParams, useRouter } from "expo-router";
|
import { useLocalSearchParams, useRouter } from "expo-router";
|
||||||
|
|
||||||
|
import type { RunnerEvent } from "@movie-web/provider-utils";
|
||||||
import {
|
import {
|
||||||
getVideoStream,
|
getVideoStream,
|
||||||
transformSearchResultToScrapeMedia,
|
transformSearchResultToScrapeMedia,
|
||||||
@@ -24,7 +25,7 @@ function LoadingScreen({ data }: { data: ItemData | null }) {
|
|||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [eventLog, setEventLog] = useState<string[]>([]);
|
const [eventLog, setEventLog] = useState<string[]>([]);
|
||||||
|
|
||||||
const handleEvent = (event: unknown) => {
|
const handleEvent = (event: RunnerEvent) => {
|
||||||
const formattedEvent = formatEvent(event);
|
const formattedEvent = formatEvent(event);
|
||||||
setEventLog((prevLog) => [...prevLog, formattedEvent]);
|
setEventLog((prevLog) => [...prevLog, formattedEvent]);
|
||||||
};
|
};
|
||||||
@@ -96,17 +97,32 @@ function LoadingScreen({ data }: { data: ItemData | null }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatEvent(event: unknown): string {
|
function formatEvent(event: RunnerEvent): string {
|
||||||
if (typeof event === "string") {
|
if (typeof event === "string") {
|
||||||
return `Start: ID - ${event}`;
|
return `Start: ID - ${event}`;
|
||||||
} else if (typeof event === "object" && event !== null) {
|
} else if (typeof event === "object" && event !== null) {
|
||||||
const evt = event as Record<string, unknown>;
|
if ("percentage" in event) {
|
||||||
if ("percentage" in evt) {
|
const evt = event;
|
||||||
return `Update: ${String(evt.percentage)}% - Status: ${String(evt.status)}`;
|
const statusMessage =
|
||||||
} else if ("sourceIds" in evt) {
|
evt.status === "success"
|
||||||
return `Initialization: Source IDs - ${String(evt.sourceIds)}`;
|
? "Completed"
|
||||||
} else if ("sourceId" in evt) {
|
: evt.status === "failure"
|
||||||
return `Discovered Embeds: Source ID - ${String(evt.sourceId)}`;
|
? "Failed - " + (evt.reason ?? "Unknown Error")
|
||||||
|
: evt.status === "notfound"
|
||||||
|
? "Not Found"
|
||||||
|
: evt.status === "pending"
|
||||||
|
? "In Progress"
|
||||||
|
: "Unknown Status";
|
||||||
|
return `Update: ${evt.percentage}% - Status: ${statusMessage}`;
|
||||||
|
} else if ("sourceIds" in event) {
|
||||||
|
const evt = event;
|
||||||
|
return `Initialization: Source IDs - ${evt.sourceIds.join(" ")}`;
|
||||||
|
} else if ("sourceId" in event) {
|
||||||
|
const evt = event;
|
||||||
|
const embedsInfo = evt.embeds
|
||||||
|
.map((embed) => `ID: ${embed.id}, Scraper: ${embed.embedScraperId}`)
|
||||||
|
.join("; ");
|
||||||
|
return `Discovered Embeds: Source ID - ${evt.sourceId} [${embedsInfo}]`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return JSON.stringify(event);
|
return JSON.stringify(event);
|
||||||
|
@@ -13,6 +13,34 @@ import {
|
|||||||
targets,
|
targets,
|
||||||
} from "@movie-web/providers";
|
} from "@movie-web/providers";
|
||||||
|
|
||||||
|
export interface InitEvent {
|
||||||
|
sourceIds: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface UpdateEvent {
|
||||||
|
id: string;
|
||||||
|
percentage: number;
|
||||||
|
status: UpdateEventStatus;
|
||||||
|
error?: unknown;
|
||||||
|
reason?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type UpdateEventStatus = "success" | "failure" | "notfound" | "pending";
|
||||||
|
|
||||||
|
export interface DiscoverEmbedsEvent {
|
||||||
|
sourceId: string;
|
||||||
|
embeds: {
|
||||||
|
id: string;
|
||||||
|
embedScraperId: string;
|
||||||
|
}[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export type RunnerEvent =
|
||||||
|
| string
|
||||||
|
| InitEvent
|
||||||
|
| UpdateEvent
|
||||||
|
| DiscoverEmbedsEvent;
|
||||||
|
|
||||||
export async function getVideoStream({
|
export async function getVideoStream({
|
||||||
media,
|
media,
|
||||||
forceVTT,
|
forceVTT,
|
||||||
@@ -20,7 +48,7 @@ export async function getVideoStream({
|
|||||||
}: {
|
}: {
|
||||||
media: ScrapeMedia;
|
media: ScrapeMedia;
|
||||||
forceVTT?: boolean;
|
forceVTT?: boolean;
|
||||||
onEvent?: (event: unknown) => void;
|
onEvent?: (event: RunnerEvent) => void;
|
||||||
}): Promise<Stream | null> {
|
}): Promise<Stream | null> {
|
||||||
const providers = makeProviders({
|
const providers = makeProviders({
|
||||||
fetcher: makeStandardFetcher(fetch),
|
fetcher: makeStandardFetcher(fetch),
|
||||||
|
Reference in New Issue
Block a user