From 8a4602fbfd9296152745a51ab3b701c16eb8dbf8 Mon Sep 17 00:00:00 2001 From: localhost Date: Thu, 18 Jan 2024 19:54:35 +0100 Subject: [PATCH] pow captcha & search --- controller/search.js | 16 +++++++++++++--- controller/websocket.js | 9 ++++++--- prisma/schema.prisma | 2 ++ utils/captcha.js | 9 ++++++--- 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/controller/search.js b/controller/search.js index b18c205..e6a7c9d 100644 --- a/controller/search.js +++ b/controller/search.js @@ -1,11 +1,21 @@ const validate = require('../utils/validate.js') +const { PrismaClient } = require('@prisma/client') +const prisma = new PrismaClient() exports.searchVideo = async (req, res) => { - const id = await validate.validateVideoInput(req.query.url) + const id = await validate.validateVideoInput(req.query.search) if (id.fail) { - res.status(500).send(id.message) + const videos = await prisma.videos.findMany({ + where: { + title: { + contains: req.query.search, + mode: 'insensitive' + } + } + }) + res.json(videos) } else { - res.send(``) + res.send(`redirect-${process.env.FRONTEND}/watch?v=${id}`) } } diff --git a/controller/websocket.js b/controller/websocket.js index 3142707..443a020 100644 --- a/controller/websocket.js +++ b/controller/websocket.js @@ -49,7 +49,8 @@ exports.save = async (ws, req) => { if (already) return ws.send(`DONE - ${process.env.FRONTEND}/watch?v=${id}`) - ws.send('CAPTCHA - Please complete the captcha:') + ws.send('DATA - This process is automatic. Your video will start archiving shortly.') + ws.send('CAPTCHA - Solving a cryptographic challenge before downloading.') ws.on('message', async function(msg) { if (msg == 'alive') return @@ -107,7 +108,8 @@ exports.playlist = async (ws, req) => { } let status = 'captcha' - ws.send('CAPTCHA - Please complete the captcha:') + ws.send('DATA - This process is automatic. Your video will start archiving shortly.') + ws.send('CAPTCHA - Solving a cryptographic challenge before downloading.') ws.on('message', async function(msg) { if (msg == 'alive') return @@ -213,7 +215,8 @@ exports.channel = async (ws, req) => { } let status = 'captcha' - ws.send('CAPTCHA - Please complete the captcha:') + ws.send('DATA - This process is automatic. Your video will start archiving shortly.') + ws.send('CAPTCHA - Solving a cryptographic challenge before downloading.') ws.on('message', async function(msg) { if (msg == 'alive') return diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 2d4a9fe..df155d2 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -25,6 +25,8 @@ model videos { channelAvatar String playlist String? disabled Boolean @default(false) + + @@index([title], name: "idx_title") } model reports { diff --git a/utils/captcha.js b/utils/captcha.js index 2a35c62..f5c4498 100644 --- a/utils/captcha.js +++ b/utils/captcha.js @@ -1,12 +1,15 @@ const fetch = require('node-fetch') async function checkCaptcha(response) { - const confirm = await (await fetch('https://hcaptcha.com/siteverify', { + const confirm = await (await fetch('https://challenges.cloudflare.com/turnstile/v0/siteverify', { method: 'POST', - body: new URLSearchParams({ + body: JSON.stringify({ 'response': response, 'secret': process.env.CAPTCHA_SECRET - }) + }), + headers: { + 'content-type': 'application/json' + } })).json() return confirm.success