mirror of
https://github.com/movie-web/providers-api.git
synced 2025-09-13 11:53:25 +00:00
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "providers-api",
|
||||
"version": "1.0.4",
|
||||
"version": "1.1.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
|
19
src/index.ts
19
src/index.ts
@@ -3,24 +3,15 @@ import { streamSSE } from 'hono/streaming';
|
||||
import { cors } from 'hono/cors';
|
||||
import {
|
||||
ScrapeMedia,
|
||||
makeProviders,
|
||||
makeStandardFetcher,
|
||||
targets,
|
||||
} from '@movie-web/providers';
|
||||
import { ZodError, z } from 'zod';
|
||||
import { embedSchema, scrapeAllSchema, sourceSchema } from '@/schema';
|
||||
import { validateTurnstile } from '@/turnstile';
|
||||
import { getProviders } from '@/providers';
|
||||
|
||||
// hono doesn't export this type, so we retrieve it from a function
|
||||
type SSEStreamingApi = Parameters<Parameters<typeof streamSSE>['1']>['0'];
|
||||
|
||||
const fetcher = makeStandardFetcher(fetch);
|
||||
|
||||
const providers = makeProviders({
|
||||
fetcher,
|
||||
target: targets.BROWSER,
|
||||
});
|
||||
|
||||
const app = new Hono();
|
||||
|
||||
function isTurnstileEnabled(context: Context<Env>) {
|
||||
@@ -103,7 +94,7 @@ app.get('/scrape', async (context) => {
|
||||
}
|
||||
|
||||
try {
|
||||
const output = await providers.runAll({
|
||||
const output = await getProviders(context).runAll({
|
||||
media,
|
||||
events: {
|
||||
discoverEmbeds(evt) {
|
||||
@@ -176,7 +167,7 @@ app.get('/scrape/embed', async (context) => {
|
||||
await writeSSEEvent(stream, 'token', jwtResponse);
|
||||
}
|
||||
try {
|
||||
const output = await providers.runEmbedScraper({
|
||||
const output = await getProviders(context).runEmbedScraper({
|
||||
id: embedInput.id,
|
||||
url: embedInput.url,
|
||||
events: {
|
||||
@@ -240,7 +231,7 @@ app.get('/scrape/source', async (context) => {
|
||||
await writeSSEEvent(stream, 'token', jwtResponse);
|
||||
}
|
||||
try {
|
||||
const output = await providers.runSourceScraper({
|
||||
const output = await getProviders(context).runSourceScraper({
|
||||
id: sourceInput.id,
|
||||
media: sourceInput,
|
||||
events: {
|
||||
@@ -268,7 +259,7 @@ app.get('/scrape/source', async (context) => {
|
||||
});
|
||||
|
||||
app.get('/metadata', async (context) => {
|
||||
return context.json([providers.listEmbeds(), providers.listSources()]);
|
||||
return context.json([getProviders(context).listEmbeds(), getProviders(context).listSources()]);
|
||||
});
|
||||
|
||||
export default app;
|
||||
|
22
src/providers.ts
Normal file
22
src/providers.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { makeProviders, makeSimpleProxyFetcher, makeStandardFetcher, targets, Fetcher as RealFetcher } from "@movie-web/providers";
|
||||
import { Context, Env } from "hono";
|
||||
|
||||
const standardFetcher = makeStandardFetcher(fetch);
|
||||
|
||||
export function getProviders(context: Context<Env>) {
|
||||
const proxyUrl = (context.env?.PROXY_URL as string | undefined) ?? '';
|
||||
const specialDomainsEnv = (context.env?.PROXIED_DOMAINS as string | undefined) ?? '';
|
||||
const specialDomains = specialDomainsEnv.split(",").map(v=>v.trim()).filter(v=>v.length>0);
|
||||
|
||||
const fetcher: RealFetcher = (u,ops) => {
|
||||
const url = new URL(u);
|
||||
if (specialDomains.includes(url.hostname) && !!proxyUrl)
|
||||
return makeSimpleProxyFetcher(proxyUrl, fetch)(u, ops);
|
||||
return standardFetcher(u, ops);
|
||||
};
|
||||
|
||||
return makeProviders({
|
||||
fetcher,
|
||||
target: targets.BROWSER,
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user