mirror of
https://github.com/movie-web/providers-api.git
synced 2025-09-13 05:33:26 +00:00
Fix Turnstile enabled, remove TODO and log, add warning to readme
This commit is contained in:
@@ -1,2 +1,5 @@
|
||||
# provider-api
|
||||
Our provider package exposed as a HTTP API
|
||||
|
||||
> **Warning**
|
||||
> This only works on Cloudflare due to CloudFlare specific logic and build processes
|
||||
|
18
src/index.ts
18
src/index.ts
@@ -1,4 +1,4 @@
|
||||
import { Hono } from 'hono';
|
||||
import { Context, Env, Hono } from 'hono';
|
||||
import { streamSSE } from 'hono/streaming';
|
||||
import { cors } from 'hono/cors';
|
||||
import {
|
||||
@@ -23,6 +23,10 @@ const providers = makeProviders({
|
||||
|
||||
const app = new Hono();
|
||||
|
||||
function isTurnstileEnabled(context: Context<Env>) {
|
||||
return (context.env?.TURNSTILE_ENABLED ?? "true") === "true"
|
||||
}
|
||||
|
||||
app.use('*', (context, next) => {
|
||||
const allowedCorsHosts = ((context.env?.CORS_ALLOWED as string) ?? '').split(
|
||||
',',
|
||||
@@ -60,11 +64,9 @@ async function writeSSEEvent(
|
||||
app.get('/scrape', async (context) => {
|
||||
const queryParams = context.req.query();
|
||||
|
||||
const turnstileEnabled = Boolean(context.env?.TURNSTILE_ENABLED);
|
||||
|
||||
let jwtResponse: string | undefined = undefined;
|
||||
|
||||
if (turnstileEnabled) {
|
||||
if (isTurnstileEnabled(context)) {
|
||||
const turnstileResponse = await validateTurnstile(context);
|
||||
|
||||
if (!turnstileResponse.success) {
|
||||
@@ -136,11 +138,9 @@ app.get('/scrape', async (context) => {
|
||||
app.get('/scrape/embed', async (context) => {
|
||||
const queryParams = context.req.query();
|
||||
|
||||
const turnstileEnabled = Boolean(context.env?.TURNSTILE_ENABLED);
|
||||
|
||||
let jwtResponse: string | undefined = undefined;
|
||||
|
||||
if (turnstileEnabled) {
|
||||
if (isTurnstileEnabled(context)) {
|
||||
const turnstileResponse = await validateTurnstile(context);
|
||||
|
||||
if (!turnstileResponse.success) {
|
||||
@@ -203,11 +203,9 @@ app.get('/scrape/embed', async (context) => {
|
||||
app.get('/scrape/source', async (context) => {
|
||||
const queryParams = context.req.query();
|
||||
|
||||
const turnstileEnabled = Boolean(context.env?.TURNSTILE_ENABLED);
|
||||
|
||||
let jwtResponse: string | undefined = undefined;
|
||||
|
||||
if (turnstileEnabled) {
|
||||
if (isTurnstileEnabled(context)) {
|
||||
const turnstileResponse = await validateTurnstile(context);
|
||||
|
||||
if (!turnstileResponse.success) {
|
||||
|
@@ -7,13 +7,10 @@ export async function validateTurnstile(context: Context<Env>) {
|
||||
|
||||
const token = context.req.query('token') || '';
|
||||
|
||||
// TODO: Make this cross platform
|
||||
const ip = context.req.header('CF-Connecting-IP') || '';
|
||||
|
||||
if (token.startsWith('jwt|')) {
|
||||
try {
|
||||
console.log(token, token.slice('jwt|'.length));
|
||||
|
||||
const isValid = await jsonwebtoken.verify(
|
||||
token.slice('jwt|'.length),
|
||||
jwtSecret,
|
||||
|
Reference in New Issue
Block a user