pow captcha & search

This commit is contained in:
localhost 2024-01-18 19:54:35 +01:00
parent e965682e33
commit 8a4602fbfd
4 changed files with 27 additions and 9 deletions

View File

@ -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(`<script>window.location.href = '${process.env.FRONTEND}/watch?v=${id}'</script>`)
res.send(`redirect-${process.env.FRONTEND}/watch?v=${id}`)
}
}

View File

@ -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

View File

@ -25,6 +25,8 @@ model videos {
channelAvatar String
playlist String?
disabled Boolean @default(false)
@@index([title], name: "idx_title")
}
model reports {

View File

@ -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