mirror of
https://github.com/movie-web/providers-api.git
synced 2025-09-13 10:23: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
|
# provider-api
|
||||||
Our provider package exposed as a HTTP 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 { streamSSE } from 'hono/streaming';
|
||||||
import { cors } from 'hono/cors';
|
import { cors } from 'hono/cors';
|
||||||
import {
|
import {
|
||||||
@@ -23,6 +23,10 @@ const providers = makeProviders({
|
|||||||
|
|
||||||
const app = new Hono();
|
const app = new Hono();
|
||||||
|
|
||||||
|
function isTurnstileEnabled(context: Context<Env>) {
|
||||||
|
return (context.env?.TURNSTILE_ENABLED ?? "true") === "true"
|
||||||
|
}
|
||||||
|
|
||||||
app.use('*', (context, next) => {
|
app.use('*', (context, next) => {
|
||||||
const allowedCorsHosts = ((context.env?.CORS_ALLOWED as string) ?? '').split(
|
const allowedCorsHosts = ((context.env?.CORS_ALLOWED as string) ?? '').split(
|
||||||
',',
|
',',
|
||||||
@@ -60,11 +64,9 @@ async function writeSSEEvent(
|
|||||||
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);
|
|
||||||
|
|
||||||
let jwtResponse: string | undefined = undefined;
|
let jwtResponse: string | undefined = undefined;
|
||||||
|
|
||||||
if (turnstileEnabled) {
|
if (isTurnstileEnabled(context)) {
|
||||||
const turnstileResponse = await validateTurnstile(context);
|
const turnstileResponse = await validateTurnstile(context);
|
||||||
|
|
||||||
if (!turnstileResponse.success) {
|
if (!turnstileResponse.success) {
|
||||||
@@ -136,11 +138,9 @@ app.get('/scrape', async (context) => {
|
|||||||
app.get('/scrape/embed', async (context) => {
|
app.get('/scrape/embed', async (context) => {
|
||||||
const queryParams = context.req.query();
|
const queryParams = context.req.query();
|
||||||
|
|
||||||
const turnstileEnabled = Boolean(context.env?.TURNSTILE_ENABLED);
|
|
||||||
|
|
||||||
let jwtResponse: string | undefined = undefined;
|
let jwtResponse: string | undefined = undefined;
|
||||||
|
|
||||||
if (turnstileEnabled) {
|
if (isTurnstileEnabled(context)) {
|
||||||
const turnstileResponse = await validateTurnstile(context);
|
const turnstileResponse = await validateTurnstile(context);
|
||||||
|
|
||||||
if (!turnstileResponse.success) {
|
if (!turnstileResponse.success) {
|
||||||
@@ -203,11 +203,9 @@ app.get('/scrape/embed', async (context) => {
|
|||||||
app.get('/scrape/source', async (context) => {
|
app.get('/scrape/source', async (context) => {
|
||||||
const queryParams = context.req.query();
|
const queryParams = context.req.query();
|
||||||
|
|
||||||
const turnstileEnabled = Boolean(context.env?.TURNSTILE_ENABLED);
|
|
||||||
|
|
||||||
let jwtResponse: string | undefined = undefined;
|
let jwtResponse: string | undefined = undefined;
|
||||||
|
|
||||||
if (turnstileEnabled) {
|
if (isTurnstileEnabled(context)) {
|
||||||
const turnstileResponse = await validateTurnstile(context);
|
const turnstileResponse = await validateTurnstile(context);
|
||||||
|
|
||||||
if (!turnstileResponse.success) {
|
if (!turnstileResponse.success) {
|
||||||
|
@@ -7,13 +7,10 @@ export async function validateTurnstile(context: Context<Env>) {
|
|||||||
|
|
||||||
const token = context.req.query('token') || '';
|
const token = context.req.query('token') || '';
|
||||||
|
|
||||||
// TODO: Make this cross platform
|
|
||||||
const ip = context.req.header('CF-Connecting-IP') || '';
|
const ip = context.req.header('CF-Connecting-IP') || '';
|
||||||
|
|
||||||
if (token.startsWith('jwt|')) {
|
if (token.startsWith('jwt|')) {
|
||||||
try {
|
try {
|
||||||
console.log(token, token.slice('jwt|'.length));
|
|
||||||
|
|
||||||
const isValid = await jsonwebtoken.verify(
|
const isValid = await jsonwebtoken.verify(
|
||||||
token.slice('jwt|'.length),
|
token.slice('jwt|'.length),
|
||||||
jwtSecret,
|
jwtSecret,
|
||||||
|
Reference in New Issue
Block a user