redirects to preservetube.com for saves, descriptive errors for tor

saves
This commit is contained in:
localhost 2026-04-05 09:53:52 +02:00
parent 3b40f50a01
commit de6f6ed61c
1 changed files with 8 additions and 3 deletions

View File

@ -18,11 +18,16 @@ app.get('/', async ({ set }) => {
})) }))
}) })
app.get('/save', async ({ query: { url }, set, headers, error }) => { app.get('/save', async ({ query: { url }, set, headers, error, request, redirect }) => {
if (headers.host?.split(':')[0] !== 'preservetube.com') {
const parsedUrl = new URL(request.url)
return redirect(`https://preservetube.com${parsedUrl.pathname}${parsedUrl.search}`)
}
if (!url) return error(400, 'No url provided.') if (!url) return error(400, 'No url provided.')
const ranges = await checkIpRanges(headers['cf-connecting-ip'] || headers['x-forwarded-for'] || '') const ranges = await checkIpRanges(headers['cf-connecting-ip'] || headers['x-forwarded-for'] || '')
if (ranges.blocked) { if (ranges.blocked || headers['cf-ipcountry'] === 'T1') {
set.headers['Content-Type'] = 'text/html; charset=utf-8' set.headers['Content-Type'] = 'text/html; charset=utf-8'
return error(412, await m(eta.render('./blocked', { return error(412, await m(eta.render('./blocked', {
title: 'Blocked | PreserveTube' title: 'Blocked | PreserveTube'
@ -54,7 +59,7 @@ app.get('/savechannel', async ({ query: { url }, set, headers, error }) => {
if (!url) return error(400, 'No url provided.') if (!url) return error(400, 'No url provided.')
const ranges = await checkIpRanges(headers['cf-connecting-ip'] || headers['x-forwarded-for'] || '') const ranges = await checkIpRanges(headers['cf-connecting-ip'] || headers['x-forwarded-for'] || '')
if (ranges.blocked) { if (ranges.blocked || headers['cf-ipcountry'] === 'T1') {
set.headers['Content-Type'] = 'text/html; charset=utf-8' set.headers['Content-Type'] = 'text/html; charset=utf-8'
return error(412, await m(eta.render('./blocked', { return error(412, await m(eta.render('./blocked', {
title: 'Blocked | PreserveTube' title: 'Blocked | PreserveTube'