feat: add shareable meme permalinks

This commit is contained in:
2026-07-24 15:37:22 -03:00
parent 4d317ba1d3
commit 0bf215555a
7 changed files with 334 additions and 33 deletions
+15
View File
@@ -75,6 +75,21 @@ const server = http.createServer(async (req, res) => {
}));
}
const memePageMatch = url.pathname.match(/^\/meme\/([a-f0-9]{64})\/?$/);
if (req.method === 'GET' && memePageMatch) {
const meme = store.get(memePageMatch[1]);
if (!meme || meme.status !== 'approved') return sendText(res, 404, 'Not found');
const nonce = crypto.randomBytes(16).toString('base64');
withSecurityHeaders(res, { scriptNonce: nonce });
return sendHtml(res, 200, renderIndex({
template: indexTemplate,
baseUrl,
nonce,
approvedCount: store.count('approved'),
meme: publicMeme(meme)
}));
}
if (req.method === 'GET' && url.pathname === '/openapi.json') {
res.setHeader('Cache-Control', 'public, max-age=300');
return sendJson(res, 200, openApiSpecFor(baseUrl));