mirror of
https://github.com/movie-web/providers-api.git
synced 2025-09-13 08:03:28 +00:00
Rename id to eventId and reformat
This commit is contained in:
42
src/index.ts
42
src/index.ts
@@ -9,7 +9,7 @@ import {
|
|||||||
import { ZodError, z } from 'zod';
|
import { ZodError, z } from 'zod';
|
||||||
|
|
||||||
const app = new Hono();
|
const app = new Hono();
|
||||||
let id = 0;
|
let eventId = 0;
|
||||||
|
|
||||||
const fetcher = makeStandardFetcher(fetch);
|
const fetcher = makeStandardFetcher(fetch);
|
||||||
|
|
||||||
@@ -26,11 +26,11 @@ async function outputEvent(
|
|||||||
return await stream.writeSSE({
|
return await stream.writeSSE({
|
||||||
event,
|
event,
|
||||||
data: JSON.stringify(data),
|
data: JSON.stringify(data),
|
||||||
id: String(id++),
|
id: String(eventId++),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const tmdbIdSchema = z.string().regex(/^\d+$/)
|
const tmdbIdSchema = z.string().regex(/^\d+$/);
|
||||||
|
|
||||||
const mediaSchema = z
|
const mediaSchema = z
|
||||||
.discriminatedUnion('type', [
|
.discriminatedUnion('type', [
|
||||||
@@ -71,39 +71,39 @@ const mediaSchema = z
|
|||||||
});
|
});
|
||||||
|
|
||||||
async function validateTurnstile(context: Context<Env>) {
|
async function validateTurnstile(context: Context<Env>) {
|
||||||
const turnstileSecret = context.env?.TURNSTILE_SECRET as string | undefined
|
const turnstileSecret = context.env?.TURNSTILE_SECRET as string | undefined;
|
||||||
|
|
||||||
const token = context.req.header("cf-turnstile-token") || ""
|
const token = context.req.header('cf-turnstile-token') || '';
|
||||||
|
|
||||||
// TODO: Make this cross platform
|
// TODO: Make this cross platform
|
||||||
const ip = context.req.header('CF-Connecting-IP') || "";
|
const ip = context.req.header('CF-Connecting-IP') || '';
|
||||||
|
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append('secret', turnstileSecret || "");
|
formData.append('secret', turnstileSecret || '');
|
||||||
formData.append('response', token);
|
formData.append('response', token);
|
||||||
formData.append('remoteip', ip);
|
formData.append('remoteip', ip);
|
||||||
|
|
||||||
const url = 'https://challenges.cloudflare.com/turnstile/v0/siteverify';
|
const url = 'https://challenges.cloudflare.com/turnstile/v0/siteverify';
|
||||||
const result = await fetch(url, {
|
const result = await fetch(url, {
|
||||||
body: formData,
|
body: formData,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
});
|
});
|
||||||
|
|
||||||
const outcome = await result.json<any>();
|
const outcome = await result.json<any>();
|
||||||
return outcome.success
|
return outcome.success;
|
||||||
}
|
}
|
||||||
|
|
||||||
app.get('/scrape', async (context) => {
|
app.get('/scrape', async (context) => {
|
||||||
const queryParams = context.req.query();
|
const queryParams = context.req.query();
|
||||||
|
|
||||||
const turnstileEnabled = Boolean(context.env?.TURNSTILE_ENABLED)
|
const turnstileEnabled = Boolean(context.env?.TURNSTILE_ENABLED);
|
||||||
|
|
||||||
if (turnstileEnabled) {
|
if (turnstileEnabled) {
|
||||||
const success = await validateTurnstile(context)
|
const success = await validateTurnstile(context);
|
||||||
|
|
||||||
if (!success) {
|
if (!success) {
|
||||||
context.status(401)
|
context.status(401);
|
||||||
return context.text("Turnstile invalid")
|
return context.text('Turnstile invalid');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,7 +142,7 @@ app.get('/scrape', async (context) => {
|
|||||||
return await outputEvent(stream, 'completed', output);
|
return await outputEvent(stream, 'completed', output);
|
||||||
}
|
}
|
||||||
|
|
||||||
stream.writeSSE({ event: 'noOutput', data: '', id: String(id++) });
|
stream.writeSSE({ event: 'noOutput', data: '', id: String(eventId++) });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user