From 4b3f487548c30c7dbb9504a8bea808ae91907820 Mon Sep 17 00:00:00 2001 From: localhost Date: Wed, 18 Feb 2026 23:16:42 +0100 Subject: [PATCH] require identifying yourself via api --- src/router/video.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/router/video.ts b/src/router/video.ts index af01b5f..ed0e157 100644 --- a/src/router/video.ts +++ b/src/router/video.ts @@ -116,7 +116,16 @@ app.get('/watch', async ({ query: { v }, set, redirect, error }) => { return html }) -app.get('/video/:id', async ({ params: { id }, error }) => { +function hasIdentifyingUA(req: Request): boolean { + const ua = req.headers.get('user-agent') ?? ''; + return /^[^\s]+\/[\d.]+ \([^)]+\)$/.test(ua); +} + +app.get('/video/:id', async ({ request, params: { id }, error }) => { + const isNice = hasIdentifyingUA(request) + if (!isNice) return `This endpoint is provided for people that prefer not to scrape, and depends on your honesty. +Please identify yourself with a User-Agent in the format: AppName/1.0 (a way for me to contact you, or a brief explanation of what you're doing).` + const cached = await redis.get(`video:${id}`) if (cached) return JSON.parse(cached)