api: add support for cloudflare turnstile
This commit is contained in:
@@ -12,7 +12,8 @@ import { languageCode } from "../misc/utils.js";
|
||||
|
||||
import { createResponse, normalizeRequest, getIP } from "../processing/request.js";
|
||||
import { verifyStream, getInternalStream } from "../stream/manage.js";
|
||||
import { randomizeCiphers } from '../misc/randomize-ciphers.js';
|
||||
import { randomizeCiphers } from "../misc/randomize-ciphers.js";
|
||||
import { verifyTurnstileToken } from "../misc/turnstile.js";
|
||||
import { extract } from "../processing/url.js";
|
||||
import match from "../processing/match.js";
|
||||
import stream from "../stream/stream.js";
|
||||
@@ -134,6 +135,23 @@ export function runAPI(express, app, __dirname) {
|
||||
return fail('ErrorNoLink');
|
||||
}
|
||||
|
||||
if (env.turnstileSecret) {
|
||||
const turnstileResponse = req.header("cf-turnstile-response");
|
||||
|
||||
if (!turnstileResponse) {
|
||||
return fail("error.api.authentication");
|
||||
}
|
||||
|
||||
const turnstileResult = await verifyTurnstileToken(
|
||||
turnstileResponse,
|
||||
req.ip
|
||||
);
|
||||
|
||||
if (!turnstileResult) {
|
||||
return fail("error.api.authentication");
|
||||
}
|
||||
}
|
||||
|
||||
if (request.youtubeDubBrowserLang) {
|
||||
request.youtubeDubLang = lang;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user