Owner (ADMIN_EMAIL) and the admin portal skip the 10-a-day upload cap (Marty 2026-11-08); members keep 10 a day

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-11-08 08:05:16 -06:00
parent eedc15bc13
commit 27a975138a
+4 -2
View File
@@ -143,6 +143,8 @@ fs.mkdirSync(DATA_DIR, { recursive: true });
const UPLOADS_DIR = path.join(DATA_DIR, 'uploads'); // solo-ad media lives on the volume
fs.mkdirSync(UPLOADS_DIR, { recursive: true });
const uploadCounts = new Map(); // email:day -> uploads today
// the owner (ADMIN_EMAIL) and the admin portal have no daily upload cap (Marty 2026-11-08); every other member keeps 10 a day
const uploadCapHit = (who, key) => who !== 'admin' && String(who || '').toLowerCase() !== ADMIN_EMAIL && (uploadCounts.get(key) || 0) >= 10;
// open earn tokens (ad view / video / visit / tour) live in memory but mirror to the volume so a
// redeploy mid-watch does not lose them (2026-09-13: a member's video watch died in a restart)
const OPEN_TOKENS_FILE = () => path.join(DATA_DIR, 'open-tokens.json');
@@ -444,7 +446,7 @@ async function handleUpload(req, res, who) {
if (!EXT[ct]) return json(res, 400, { error: 'Use a PNG, JPG, WebP, GIF, MP4 or WebM file.' });
const isVideo = ct.startsWith('video/');
const key = who + ':' + new Date().toISOString().slice(0, 10);
if ((uploadCounts.get(key) || 0) >= 10) return json(res, 400, { error: 'Upload limit for today reached (10 files).' });
if (uploadCapHit(who, key)) return json(res, 400, { error: 'Upload limit for today reached (10 files).' });
let buf;
try { buf = await readRaw(req, isVideo ? 25 * 1024 * 1024 : 3 * 1024 * 1024); }
catch (e) { return json(res, 400, { error: 'File too large. Images up to 3MB, video up to 25MB.' }); }
@@ -2695,7 +2697,7 @@ const server = http.createServer(async (req, res) => {
const EXT = { 'image/png': 'png', 'image/jpeg': 'jpg', 'image/gif': 'gif' };
if (!EXT[ct]) return json(res, 400, { error: 'Use a JPG, PNG or GIF file.' });
const key = s.email + ':' + new Date().toISOString().slice(0, 10);
if ((uploadCounts.get(key) || 0) >= 10) return json(res, 400, { error: 'Upload limit for today reached (10 files).' });
if (uploadCapHit(s.email, key)) return json(res, 400, { error: 'Upload limit for today reached (10 files).' });
let buf; try { buf = await readRaw(req, bannerspin.MAX_BYTES); } catch (e) { return json(res, 400, { error: 'That image is over 150 KB. Save it smaller (fewer colors or frames for a GIF) and try again.' }); }
const magicOk = buf.length > 16 && ((ct === 'image/png' && buf[0] === 0x89 && buf[1] === 0x50 && buf[2] === 0x4e && buf[3] === 0x47) || (ct === 'image/jpeg' && buf[0] === 0xff && buf[1] === 0xd8 && buf[2] === 0xff) || (ct === 'image/gif' && buf.slice(0, 4).toString() === 'GIF8'));
if (!magicOk) return json(res, 400, { error: 'That file does not look like a real ' + EXT[ct].toUpperCase() + '.' });