| ... | @@ -13,8 +13,20 @@ app.get("/file/*", async (c, next) => { | ... | @@ -13,8 +13,20 @@ app.get("/file/*", async (c, next) => { |
| 13 | const ua = c.req.header("User-Agent")?.toLowerCase() ?? ""; | 13 | const ua = c.req.header("User-Agent")?.toLowerCase() ?? ""; |
| 14 | const lofi = ua.includes("msie") || false; | 14 | const lofi = ua.includes("msie") || false; |
| 15 | | 15 | |
| 16 | // Discord ignores 'robots.txt' which violates the license agreement. | 16 | // Some robots ignore 'robots.txt' which violates the license agreement. |
| 17 | if (ua.includes("discordbot")) return c.body("Forbidden", 403); | 17 | if ( |
| | 18 | (!ua.startsWith("mozilla/")) || |
| | 19 | ua.includes("headless") || |
| | 20 | ua.includes("discord") |
| | 21 | ) { |
| | 22 | return c.body( |
| | 23 | "Forbidden\n\nYour user agent, " + JSON.stringify(ua) + |
| | 24 | ", appears to be an automated. Please do not automate " + |
| | 25 | "access into my file viewer. I do not appreciate scraping. " + |
| | 26 | "Instead, please view manually in a standard web browser.", |
| | 27 | 403, |
| | 28 | ); |
| | 29 | } |
| 18 | | 30 | |
| 19 | let rawFilePath = c.req.path.slice(5) || "/"; | 31 | let rawFilePath = c.req.path.slice(5) || "/"; |
| 20 | | 32 | |