mirror of
https://github.com/movie-web/providers.git
synced 2025-09-13 17:43:25 +00:00
not found reasons + json parsing
This commit is contained in:
@@ -5,12 +5,11 @@ import { makeFullUrl } from '@/fetchers/common';
|
|||||||
import { Fetcher } from '@/fetchers/types';
|
import { Fetcher } from '@/fetchers/types';
|
||||||
|
|
||||||
export function makeStandardFetcher(f: typeof fetch): Fetcher {
|
export function makeStandardFetcher(f: typeof fetch): Fetcher {
|
||||||
const normalFetch: Fetcher = (url, ops) => {
|
const normalFetch: Fetcher = async (url, ops) => {
|
||||||
const fullUrl = makeFullUrl(url, ops);
|
const fullUrl = makeFullUrl(url, ops);
|
||||||
|
|
||||||
const seralizedBody = serializeBody(ops.body);
|
const seralizedBody = serializeBody(ops.body);
|
||||||
|
|
||||||
return f(fullUrl, {
|
const res = await f(fullUrl, {
|
||||||
method: ops.method,
|
method: ops.method,
|
||||||
headers: {
|
headers: {
|
||||||
...seralizedBody.headers,
|
...seralizedBody.headers,
|
||||||
@@ -18,6 +17,10 @@ export function makeStandardFetcher(f: typeof fetch): Fetcher {
|
|||||||
},
|
},
|
||||||
body: seralizedBody.body,
|
body: seralizedBody.body,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const isJson = res.headers.get('content-type')?.includes('application/json');
|
||||||
|
if (isJson) return res.json();
|
||||||
|
return res.text();
|
||||||
};
|
};
|
||||||
|
|
||||||
return normalFetch;
|
return normalFetch;
|
||||||
|
@@ -3,7 +3,8 @@ export type UpdateEventStatus = 'success' | 'failure' | 'notfound' | 'pending';
|
|||||||
export type UpdateEvent = {
|
export type UpdateEvent = {
|
||||||
percentage: number;
|
percentage: number;
|
||||||
status: UpdateEventStatus;
|
status: UpdateEventStatus;
|
||||||
error?: unknown;
|
error?: unknown; // set when status is failure
|
||||||
|
reason?: string; // set when status is not-found
|
||||||
};
|
};
|
||||||
|
|
||||||
export type InitEvent = {
|
export type InitEvent = {
|
||||||
|
@@ -79,6 +79,7 @@ export async function runAllProviders(list: ProviderList, ops: ProviderRunnerOpt
|
|||||||
ops.events?.update?.({
|
ops.events?.update?.({
|
||||||
percentage: 100,
|
percentage: 100,
|
||||||
status: 'notfound',
|
status: 'notfound',
|
||||||
|
reason: err.message,
|
||||||
});
|
});
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -133,6 +134,7 @@ export async function runAllProviders(list: ProviderList, ops: ProviderRunnerOpt
|
|||||||
ops.events?.update?.({
|
ops.events?.update?.({
|
||||||
percentage: 100,
|
percentage: 100,
|
||||||
status: 'notfound',
|
status: 'notfound',
|
||||||
|
reason: err.message,
|
||||||
});
|
});
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@@ -11,7 +11,7 @@ export const flixhqScraper = makeSourcerer({
|
|||||||
rank: 100,
|
rank: 100,
|
||||||
async scrapeMovie(ctx) {
|
async scrapeMovie(ctx) {
|
||||||
const id = await getFlixhqId(ctx, ctx.media);
|
const id = await getFlixhqId(ctx, ctx.media);
|
||||||
if (!id) throw new NotFoundError();
|
if (!id) throw new NotFoundError('no search results match');
|
||||||
|
|
||||||
const sources = await getFlixhqSources(ctx, id);
|
const sources = await getFlixhqSources(ctx, id);
|
||||||
const upcloudStream = sources.find((v) => v.embed.toLowerCase() === 'upcloud');
|
const upcloudStream = sources.find((v) => v.embed.toLowerCase() === 'upcloud');
|
||||||
|
Reference in New Issue
Block a user