diff --git a/server.js b/server.js index 4ea8f17..521c55a 100644 --- a/server.js +++ b/server.js @@ -259,6 +259,13 @@ const server = http.createServer(async (req, res) => { const name = path.basename(p); if (!/^[a-z0-9-]+\.(png|jpg|gif)$/.test(name)) { res.writeHead(404); return res.end(); } return sendFile(res, path.join(C.dataDir, 'art', name), { 'Cache-Control': 'public, max-age=86400' }); } + // old site links (2026-11-13): referral links were /? (bare query) and pages were *.php. An old username maps to + // the same person's network username (oldrefs.json, matched by email); a page address goes home. + if (/\.php$/i.test(p) || (p === '/' && /^[A-Za-z0-9_.-]{2,40}$/.test(u.search.slice(1).split('&')[0]))) { // "&fbclid=..." may follow + const old = /\.php$/i.test(p) && p !== '/index.php' ? '' : u.search.slice(1).split('&')[0].toLowerCase(); + let OR = {}; try { OR = JSON.parse(fs.readFileSync(path.join(C.dataDir, 'oldrefs.json'), 'utf8')); } catch (e) {} + const net = old && OR[old]; res.writeHead(301, { Location: net ? '/?ref=' + encodeURIComponent(net) : '/', 'Cache-Control': 'no-store' }); return res.end(); + } const wm = /^\/w\/([a-z0-9]{8,16})$/.exec(p); if (wm) { const ok = !!WELCOME()[wm[1]]; @@ -445,6 +452,7 @@ const server = http.createServer(async (req, res) => { const tok = process.env.ADMIN_TOKEN; if (!tok || req.headers['x-admin-token'] !== tok) return json(res, 401, { error: 'no' }); const raw = (await readRaw(req, 4 * 1024 * 1024)).toString('utf8'); let b; try { b = JSON.parse(raw); } catch (e) { return json(res, 400, { error: 'bad json' }); } const cur = WELCOME(); let n = 0; + if (b.oldrefs && typeof b.oldrefs === 'object') { const o = {}; for (const [k, v] of Object.entries(b.oldrefs)) if (/^[a-z0-9_.-]{2,40}$/.test(k) && /^[a-z0-9_]{1,20}$/.test(String(v))) o[k] = String(v); fs.writeFileSync(path.join(C.dataDir, 'oldrefs.json'), JSON.stringify(o)); } for (const [code, v] of Object.entries(b.codes || {})) { if (!/^[a-z0-9]{8,16}$/.test(code) || !v || !Array.isArray(v.line)) continue; cur[code] = { line: v.line.map(x => String(x).toLowerCase()).slice(0, 25), at: Date.now() }; n++; } fs.writeFileSync(path.join(C.dataDir, 'welcome.json'), JSON.stringify(cur)); return json(res, 200, { ok: true, added: n, total: Object.keys(cur).length });