diff --git a/src/file-viewer/backend.tsx b/src/file-viewer/backend.tsx index 6e28496c0f3451ab784cdaea27a264fd91839bf1..7ea041ee08a316548e1864390b7ec1ddffd64876 100644 --- a/src/file-viewer/backend.tsx +++ b/src/file-viewer/backend.tsx @@ -13,8 +13,20 @@ app.get("/file/*", async (c, next) => { const ua = c.req.header("User-Agent")?.toLowerCase() ?? ""; const lofi = ua.includes("msie") || false; - // Discord ignores 'robots.txt' which violates the license agreement. - if (ua.includes("discordbot")) return c.body("Forbidden", 403); + // Some robots ignore 'robots.txt' which violates the license agreement. + if ( + (!ua.startsWith("mozilla/")) || + ua.includes("headless") || + ua.includes("discord") + ) { + return c.body( + "Forbidden\n\nYour user agent, " + JSON.stringify(ua) + + ", appears to be an automated. Please do not automate " + + "access into my file viewer. I do not appreciate scraping. " + + "Instead, please view manually in a standard web browser.", + 403, + ); + } let rawFilePath = c.req.path.slice(5) || "/";