Videos: reject a source that does not load, and stop stranding the viewer

Michael Camire reported the video tab locking up after the fifth watch each
day. Three separate faults behind it.

A campaign could go live with a video address that resolves nowhere, because
the form only checked the shape of the URL. One has been sitting there since
11 September pointing at the example host, serving every Tier 1 member a black
player it could never finish. The create route now fetches the address and
refuses a host that does not answer, a 404, or a page that is not a video.

The Watch tab holds the landscape videos and Shorts holds the upright ones,
but they share one daily count. A member who cleared the tab was told to come
back tomorrow while clips were still waiting one tap away. When the other
surface still has something, the done screen now says so and links to it.

When a browser refused to autoplay, the button offered "Tap to play" but was
wired to fetch a different video, so the loaded one was thrown away and the
next also would not start. On a phone the clip could never be played at all.
The button now starts what is already loaded.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-09-22 16:54:31 -05:00
parent 68a92c39ff
commit ce9f3e6904
3 changed files with 56 additions and 9 deletions
+28 -1
View File
@@ -368,6 +368,24 @@ async function imageCheck(url) {
return { ok: false, reason: 'That link is a web page, not an image. Paste the direct image link (it usually ends in .png or .jpg), or use Promo tools > Banners > Copy image URL.' };
} catch (e) { return { ok: false, reason: 'Could not load that image link. Paste the direct image link (ends in .png or .jpg), or use Promo tools > Banners > Copy image URL.' }; }
}
// A video campaign's source has to actually exist. The create form only matched the URL
// shape, so a placeholder (yourdomain.com/....mp4) went live on 2026-09-11 and sat there for
// eleven days handing every Tier 1 viewer a black player they could never finish.
async function videoCheck(url) {
const u = String(url || '').trim();
if (/^\/uploads\//.test(u)) return { ok: true }; // uploaded here, already on our disk
let h;
try { h = await headUrl(u); }
catch (e) { // no DNS, refused, timed out
return { ok: false, reason: 'We could not reach that video link, so members would just see a black player. Check the address, or upload the file here instead.' };
}
if (h && (h.status === 404 || h.status === 410))
return { ok: false, reason: 'That video link answers with HTTP ' + h.status + ' — the file is not there. Point the campaign at a file that loads, or upload it here.' };
const ct = String((h && h.contentType) || '').split(';')[0].trim().toLowerCase();
if (ct && !/^video\//.test(ct) && ct !== 'application/octet-stream' && ct !== 'binary/octet-stream')
return { ok: false, reason: 'That link returns ' + ct + ', not a video file. Paste the direct .mp4 or .webm link, or upload the file here.' };
return { ok: true };
}
function headUrl(url) {
return new Promise((resolve, reject) => {
let u; try { u = new URL(url); } catch (e) { return reject(new Error('bad url')); }
@@ -2637,7 +2655,15 @@ const server = http.createServer(async (req, res) => {
const ad = await ads.serveVideo(Object.assign({ excludeEmail: s.email, orientation }, viewerGeo(req))); // never your own video
if (!ad) { // distinguish "you have watched every live video today" from "nothing is live" (Marty, 2026-09-13)
let allWatched = false; try { allWatched = !!(await ads.serveVideo(Object.assign({ excludeEmail: s.email, orientation, ignoreSeen: true }, viewerGeo(req)))); } catch (e) {}
return json(res, 200, { ad: null, status, allWatched });
// this surface is empty but the other one may not be: the Watch tab holds the landscape
// videos and Shorts holds the portrait ones, and they share one daily cap, so a member
// who runs the tab dry still has clips waiting (Marty, 2026-09-22)
let otherFormat = null;
if (status.left > 0 && (orientation === 'landscape' || orientation === 'portrait')) {
const alt = orientation === 'landscape' ? 'portrait' : 'landscape';
try { if (await ads.serveVideo(Object.assign({ excludeEmail: s.email, orientation: alt }, viewerGeo(req)))) otherFormat = alt === 'portrait' ? 'shorts' : 'watch'; } catch (e) {}
}
return json(res, 200, { ad: null, status, allWatched, otherFormat });
}
const token = crypto.randomBytes(16).toString('hex');
videoTokens.set(s.email, { token, ts: Date.now(), id: ad.id, secs: ad.watchSecs });
@@ -2827,6 +2853,7 @@ const server = http.createServer(async (req, res) => {
const fc = await frameCheck(b.targetUrl);
if (!fc.ok) return json(res, 400, { error: fc.reason });
}
if (String(b.type) === 'video') { const vc = await videoCheck(b.videoUrl); if (!vc.ok) return json(res, 400, { error: vc.reason }); }
// charge the best-funded of the member's positions (main + Qualified Start
// wallets). A campaign burns from one member id, so the budget must fit inside it.
const ids = (await myMemberIds(s)).ids;