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') {
|
if (await redis.get(videoId) !== 'downloading') {
|
||||||
await redis.set(videoId, 'downloading', 'EX', 300)
|
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);
|
await cleanup(ws, videoId);
|
||||||
|
console.log(`captcha failed for ${videoId} - ${JSON.stringify(captchaCheck)}`)
|
||||||
return sendError(ws, 'Captcha validation failed.');
|
return sendError(ws, 'Captcha validation failed.');
|
||||||
} else {
|
} else {
|
||||||
ws.send('DATA - Captcha validated. Starting download...');
|
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.');
|
if (!status || !status.startsWith('captcha-')) return sendError(ws, 'No channel associated with this session.');
|
||||||
|
|
||||||
const channelId = status.replace('captcha-', '');
|
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);
|
await cleanup(ws, channelId);
|
||||||
|
console.log(`captcha failed for ${channelId} - ${JSON.stringify(captchaCheck)}`)
|
||||||
return sendError(ws, 'Captcha validation failed.');
|
return sendError(ws, 'Captcha validation failed.');
|
||||||
} else {
|
} else {
|
||||||
ws.send('DATA - Captcha validated. Starting download...');
|
ws.send('DATA - Captcha validated. Starting download...');
|
||||||
|
|
|
||||||
|
|
@ -36,19 +36,21 @@ function convertRelativeToDate(relativeTime: string) {
|
||||||
return currentDate;
|
return currentDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function checkCaptcha(response: string) {
|
async function checkCaptcha(response: string, remoteIp: string): any {
|
||||||
const confirm = await (await fetch('https://challenges.cloudflare.com/turnstile/v0/siteverify', {
|
const confirm = await (await fetch('https://api.hcaptcha.com/siteverify', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify({
|
body: new URLSearchParams({
|
||||||
'response': response,
|
'response': response,
|
||||||
'secret': process.env.CAPTCHA_SECRET
|
'secret': process.env.CAPTCHA_SECRET!,
|
||||||
|
'remoteip': remoteIp,
|
||||||
|
'sitekey': process.env.SITEKEY!
|
||||||
}),
|
}),
|
||||||
headers: {
|
headers: {
|
||||||
'content-type': 'application/json'
|
'content-type': 'application/x-www-form-urlencoded'
|
||||||
}
|
}
|
||||||
})).json()
|
})).json()
|
||||||
|
|
||||||
return confirm.success
|
return confirm
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createDatabaseVideo(id: string, videoUrl: string) {
|
async function createDatabaseVideo(id: string, videoUrl: string) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue