funny bit

This commit is contained in:
ewin 2025-09-22 10:07:11 -04:00
commit 725cae593c
Signed by: erin
SSH key fingerprint: SHA256:swjoHhREbZPbWe+gyJNi24d4NAxJSyUIm3fpZj4z3wc
3 changed files with 29 additions and 0 deletions

27
fix.mjs Normal file
View file

@ -0,0 +1,27 @@
import {createServer} from 'node:http';
const sites = [
{
pattern: /^(?:https?:\/\/)?(?:www\.)pixiv\.net\/\w+\/artworks\/(\d+)(?:#(\d+))?/i,
redirect: match => `https://pixiv.kmn5.li/${match[1]}${match[2] ? `_${parseInt(match[2], 10) - 1}` : ''}`,
},
{
pattern: /^(?:https?:\/\/)?(?:www\.)?(?:twitter\.com|x\.com)\/(.+)/,
redirect: match => `https://fxtwitter.com/${match[1]}`,
},
// idk send me more of these
];
createServer(async (request, response) => {
const error = () => response.writeHead(400).end('whar');
if (request.method !== 'GET') return error();
const input = request.url.slice(1);
console.log(input);
for (const site of sites) {
let match = input.match(site.pattern);
if (!match) continue;
response.writeHead(302, {'Location': site.redirect(match)}).end();
return;
}
return error();
}).listen(process.env.PORT || 80);