switch to hcaptcha
This commit is contained in:
parent
940c1421e5
commit
6bdcfa7e8a
|
|
@ -107,8 +107,10 @@ app.ws('/save', {
|
|||
if (await redis.get(videoId) !== 'downloading') {
|
||||
await redis.set(videoId, 'downloading', 'EX', 300)
|
||||
|
||||
if (!(await checkCaptcha(message))) {
|
||||
const captchaCheck = await checkCaptcha(message, ws.data.headers['cf-connecting-ip'] || '0.0.0.0')
|
||||
if (!captchaCheck.success) {
|
||||
await cleanup(ws, videoId);
|
||||
console.log(`captcha failed for ${videoId} - ${JSON.stringify(captchaCheck)}`)
|
||||
return sendError(ws, 'Captcha validation failed.');
|
||||
} else {
|
||||
ws.send('DATA - Captcha validated. Starting download...');
|
||||
|
|
@ -158,8 +160,11 @@ app.ws('/savechannel', {
|
|||
if (!status || !status.startsWith('captcha-')) return sendError(ws, 'No channel associated with this session.');
|
||||
|
||||
const channelId = status.replace('captcha-', '');
|
||||
if (!(await checkCaptcha(message))) {
|
||||
const captchaCheck = await checkCaptcha(message, ws.data.headers['cf-connecting-ip'] || '0.0.0.0')
|
||||
|
||||
if (!captchaCheck.success) {
|
||||
await cleanup(ws, channelId);
|
||||
console.log(`captcha failed for ${channelId} - ${JSON.stringify(captchaCheck)}`)
|
||||
return sendError(ws, 'Captcha validation failed.');
|
||||
} else {
|
||||
ws.send('DATA - Captcha validated. Starting download...');
|
||||
|
|
|
|||
|
|
@ -36,19 +36,21 @@ function convertRelativeToDate(relativeTime: string) {
|
|||
return currentDate;
|
||||
}
|
||||
|
||||
async function checkCaptcha(response: string) {
|
||||
const confirm = await (await fetch('https://challenges.cloudflare.com/turnstile/v0/siteverify', {
|
||||
async function checkCaptcha(response: string, remoteIp: string): any {
|
||||
const confirm = await (await fetch('https://api.hcaptcha.com/siteverify', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
body: new URLSearchParams({
|
||||
'response': response,
|
||||
'secret': process.env.CAPTCHA_SECRET
|
||||
'secret': process.env.CAPTCHA_SECRET!,
|
||||
'remoteip': remoteIp,
|
||||
'sitekey': process.env.SITEKEY!
|
||||
}),
|
||||
headers: {
|
||||
'content-type': 'application/json'
|
||||
'content-type': 'application/x-www-form-urlencoded'
|
||||
}
|
||||
})).json()
|
||||
|
||||
return confirm.success
|
||||
return confirm
|
||||
}
|
||||
|
||||
async function createDatabaseVideo(id: string, videoUrl: string) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue