Video Spin: one short link that rotates through video pages on Social Tube; Social Tube as a network link + traffic source

Links > Video Spins (third view). A Video Spin is a spin link (rotator kind 'video'): its videos are picked from the member's own Video App
Income videos or added by any member's Social Tube address, each checked with Video App Income over signed calls (NETCONV_SECRET_VAI,
prefix vspin.v1.). Pasted addresses are refused on a Video Spin. Per video: clicks here plus opened / played / tapped from Video App Income.
Limits mirror Banner Spin (Starter 2x5, Builder 5x15, Leader 10x25), counted apart from spin links. Network link nwst + source socialtube;
socialtube.club gets the click id. Chatbot answer video-spin, KNOWLEDGE_DATE 2026-11-22 (Marty 2026-11-22).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-11-22 12:29:54 -06:00
parent a6c36aeca1
commit bca3666ee2
9 changed files with 232 additions and 12 deletions
+79 -5
View File
@@ -249,6 +249,27 @@ async function bannerFacts(email) {
// Tool tiers for spin links and pages (Marty 2026-10-21: "cap this ... and there needs to be more of an incentive for
// upgrading"): free 3, Starter (any package of your own) 10, Builder (2 qualifying buyers) 50, Leader (5) unlimited with a
// fair-use ceiling. Existing items above a cap are never removed; only new ones wait for the upgrade.
// Video Spin (2026-11-22). Limits by tool tier, mirroring Banner Spin. The picker and the play counts come from Video App Income over
// signed calls: X-Ls-Ts + X-Ls-Sig = HMAC-SHA256(NETCONV_SECRET_VAI, 'vspin.v1.' + ts + '\n' + raw). VAI_URL defaults to the live site.
const VS_LIMITS = { free: { spins: 0, videos: 0 }, starter: { spins: 2, videos: 5 }, builder: { spins: 5, videos: 15 }, leader: { spins: 10, videos: 25 } };
const VAI_URL = () => String(process.env.VAI_URL || 'https://videoappincome.com').trim().replace(/\/+$/, '');
const vsSecret = () => String(process.env.NETCONV_SECRET_VAI || '').trim();
const vsOn = () => vsSecret().length >= 32;
async function vaiCall(op, body) {
const raw = JSON.stringify(body), ts = String(Date.now());
const r = await fetch(VAI_URL() + '/api/partner/ls/' + op, { method: 'POST', headers: { 'content-type': 'application/json', 'x-ls-ts': ts, 'x-ls-sig': crypto.createHmac('sha256', vsSecret()).update('vspin.v1.' + ts + '\n' + raw).digest('hex') }, body: raw, signal: AbortSignal.timeout(12000) });
return { s: r.status, j: await r.json().catch(() => ({})) };
}
// the video's page: the address Video App Income gives for it when it is a plain watch address for that id, else the known one
const vsWatchUrl = x => { const u = String((x && x.url) || ''), id = String((x && x.id) || ''); return u.startsWith('http') && !u.includes('?') && !u.includes('#') && u.endsWith('/watch/' + id) && u.length < 200 && (!IS_PROD || u.startsWith('https://socialtube.club/')) ? u : 'https://socialtube.club/watch/' + id; };
const vsMineCache = new Map(); // email -> { ts, v }: the member's own Social Tube videos, kept one minute
async function vsMine(email) {
const e = String(email || '').toLowerCase(), hit = vsMineCache.get(e); if (hit && Date.now() - hit.ts < 60000) return hit.v;
if (!vsOn()) return { member: null, videos: [] };
let username = ''; try { const a = await accounts.byEmail(e); username = (a && a.username) || ''; } catch (er) {}
const x = await vaiCall('videos', { email: e, username }); if (x.s !== 200) throw new Error('vai ' + x.s);
const v = { member: x.j.member || null, videos: Array.isArray(x.j.videos) ? x.j.videos : [] }; vsMineCache.set(e, { ts: Date.now(), v }); return v;
}
const TOOL_TIERS = { free: { label: 'Free', max: 3, need: '' }, starter: { label: 'Starter', max: 10, need: 'any package of your own' },
builder: { label: 'Builder', max: 50, need: 'level 2 open (2 qualifying buyers)' }, leader: { label: 'Leader', max: 500, unlimited: true, need: 'level 3 open (5 qualifying buyers)' } };
const TOOL_ORDER = ['free', 'starter', 'builder', 'leader'];
@@ -950,7 +971,7 @@ function readRaw(req, maxBytes) {
// the image pixel cannot read the thank-you page's address, but a browser that sends the full referrer hands it to us
function refClickId(req) { try { const r = new URL(String(req.headers.referer || '')); const v = r.searchParams.get('lsclk') || r.searchParams.get('lsid') || ''; return /^[a-z0-9]{6,24}$/i.test(v) ? v : ''; } catch (e) { return ''; } }
// the sites of the network a click id may travel to (the landing tag's list, 2026-11-07): this site, InstantAdPay, its share domains
const NETWORK_HOSTS = String(process.env.NETWORK_HOSTS || 'instantadpay.com,instantadpay.link,ctbgo.com,mylinehq.com,videoappincome.com,clickvidpro.com').split(',').map(x => x.trim().toLowerCase()).filter(Boolean);
const NETWORK_HOSTS = String(process.env.NETWORK_HOSTS || 'instantadpay.com,instantadpay.link,ctbgo.com,mylinehq.com,videoappincome.com,clickvidpro.com,socialtube.club').split(',').map(x => x.trim().toLowerCase()).filter(Boolean);
function networkHosts() { return [...new Set([String(SITE_HOST || '').toLowerCase().replace(/:\d+$/, '').replace(/^www\./, '')].concat(NETWORK_HOSTS))].filter(Boolean); }
function clickCookie(id) { return 'ls.clk=' + id + '; Path=/; Max-Age=2592000; ' + (IS_PROD ? 'SameSite=None; Secure' : 'SameSite=Lax'); }
// an ad click: record a click id for the campaign and append ?lsclk=<id> to the target (existing params kept, an lsclk
@@ -2801,15 +2822,65 @@ const server = http.createServer(async (req, res) => {
return json(res, r.error ? 400 : 200, r);
}
// -- the rotator (LinkSpin core tool)
// ── Video Spin (Marty 2026-11-22): one short link that rotates through video pages on Social Tube. It IS a spin link (rotator.js, kind
// 'video'), so pausing, weights, schedules, health checks, sources and reports are the rotator's own. What is new: the videos are picked,
// not pasted (the member's own from Video App Income, or any member's by its Social Tube link, checked there), and the report adds plays
// from Video App Income. Limits mirror Banner Spin: Starter 2 x 5, Builder 5 x 15, Leader 10 x 25.
if (p === '/api/my/videospins' && req.method === 'GET') {
const s = await auth.fromRequest(req); if (!s || !s.email) return json(res, 401, { error: 'Sign in first.' });
const sc = siteConfig(); const hosts = String(sc.linkDomains || '').split(',').map(x => x.trim()).filter(Boolean);
const t = await toolTier(s.email), lim = VS_LIMITS[t.key] || VS_LIMITS.free; let mine = { member: null, videos: [] }, vaiError = '';
try { mine = await vsMine(s.email); } catch (e) { vaiError = 'Video App Income is not answering right now. Your Video Spins still work.'; }
return json(res, 200, { spins: (await rotator.list(s.email)).filter(x => x.kind === 'video'), hosts: hosts.length ? hosts : [SITE_HOST], tier: t, limits: lim, member: mine.member, videos: mine.videos, vaiError, on: vsOn() }, { 'Cache-Control': 'no-store' });
}
if (p === '/api/my/videospins' && req.method === 'POST') {
const s = await auth.fromRequest(req); if (!s || !s.email) return json(res, 401, { error: 'Sign in first.' });
if (!vsOn()) return json(res, 503, { error: 'Video Spins are not switched on yet.' });
const b = await readBody(req), t = await toolTier(s.email), lim = VS_LIMITS[t.key] || VS_LIMITS.free, have = (await rotator.list(s.email)).filter(x => x.kind === 'video').length;
if (!lim.spins) return json(res, 400, { error: 'Video Spins start at the Starter tier (any package of your own).', tier: t });
if (have >= lim.spins) return json(res, 400, { error: 'Your ' + t.label + ' tier holds ' + lim.spins + ' Video Spins and you have ' + have + '.', tier: t });
let mine = { member: null }; try { mine = await vsMine(s.email); } catch (e) {}
const ref = mine.member ? mine.member.username || mine.member.id : '';
const r = await rotator.create(s.email, { name: b.name, fallback: 'https://socialtube.club/' + (ref ? '?ref=' + encodeURIComponent(ref) : ''), kind: 'video', vref: ref });
return json(res, r.error ? 400 : 200, r);
}
m = /^\/api\/my\/videospins\/(\d+)\/add$/.exec(p);
if (m && req.method === 'POST') {
const s = await auth.fromRequest(req); if (!s || !s.email) return json(res, 401, { error: 'Sign in first.' });
if (!vsOn()) return json(res, 503, { error: 'Video Spins are not switched on yet.' });
const rot = (await rotator.list(s.email)).find(x => x.id === Number(m[1]) && x.kind === 'video'); if (!rot) return json(res, 404, { error: 'No such Video Spin.' });
const b = await readBody(req), t = await toolTier(s.email), lim = VS_LIMITS[t.key] || VS_LIMITS.free, raw = rotator._json.state().rotations.find(x => x.id === rot.id);
const picks = []; // { id, title, owner, poster }
try {
const ids = (Array.isArray(b.ids) ? b.ids : []).map(String).filter(x => /^[A-Za-z0-9]{1,20}$/.test(x)).slice(0, 25);
if (ids.length) { const mine = await vsMine(s.email); for (const id of ids) { const vd = mine.videos.find(x => x.id === id); if (vd) picks.push(vd); } if (picks.length !== ids.length) return json(res, 400, { error: 'One of those is not a video of yours on Social Tube. Reload and pick again.' }); }
const link = String(b.link || '').trim();
if (link) { const x = await vaiCall('video', { link }); if (x.s !== 200 || !x.j.video) return json(res, 400, { error: (x.j && x.j.error) || 'That video link could not be checked.' }); picks.push(x.j.video); }
} catch (e) { return json(res, 502, { error: 'Video App Income is not answering right now. Nothing was added. Try again in a minute.' }); }
if (!picks.length) return json(res, 400, { error: 'Pick at least one video, or paste a Social Tube video link.' });
const fresh = picks.filter((x, i) => !rot.destinations.some(d => d.vid === x.id) && picks.findIndex(y => y.id === x.id) === i);
if (!fresh.length) return json(res, 400, { error: picks.length === 1 ? 'That video is already in this Video Spin.' : 'Those videos are already in this Video Spin.' });
if (rot.destinations.length + fresh.length > lim.videos) return json(res, 400, { error: 'Your ' + t.label + ' tier holds ' + lim.videos + ' videos in one Video Spin. This one has ' + rot.destinations.length + '.', tier: t });
let out = null;
for (const x of fresh) { out = await rotator.addDest(s.email, rot.id, { url: vsWatchUrl(x) + '?vs=' + rot.code + (raw && raw.vref ? '&ref=' + encodeURIComponent(raw.vref) : ''), label: String(x.title || 'Video').slice(0, 60), weight: 10 }, { video: x }); if (out.error) return json(res, 400, out); }
return json(res, 200, { ok: true, added: fresh.length, rotation: out.rotation });
}
m = /^\/api\/my\/videospins\/(\d+)\/plays$/.exec(p);
if (m && req.method === 'GET') { // what happened on the video pages themselves, counted by Video App Income for this Video Spin's code
const s = await auth.fromRequest(req); if (!s || !s.email) return json(res, 401, { error: 'Sign in first.' });
const rot = (await rotator.list(s.email)).find(x => x.id === Number(m[1]) && x.kind === 'video'); if (!rot) return json(res, 404, { error: 'No such Video Spin.' });
try { const x = await vaiCall('stats', { code: rot.code, ids: rot.destinations.map(d => d.vid).filter(Boolean) }); return json(res, 200, { ok: true, plays: (x.s === 200 && x.j.stats) || {} }, { 'Cache-Control': 'no-store' }); }
catch (e) { return json(res, 200, { ok: true, plays: {}, vaiError: 'Play counts are not available right now.' }); }
}
if (p === '/api/my/rotations' && req.method === 'GET') {
const s = await auth.fromRequest(req); if (!s || !s.email) return json(res, 401, { error: 'Sign in first.' });
const sc = siteConfig(); const hosts = String(sc.linkDomains || '').split(',').map(x => x.trim()).filter(Boolean);
return json(res, 200, { rotations: await rotator.list(s.email), hosts: hosts.length ? hosts : [SITE_HOST], tier: await toolTier(s.email) }, { 'Cache-Control': 'no-store' });
return json(res, 200, { rotations: (await rotator.list(s.email)).filter(x => !x.kind), hosts: hosts.length ? hosts : [SITE_HOST], tier: await toolTier(s.email) }, { 'Cache-Control': 'no-store' }); // Video Spins have their own screen and limits
}
if (p === '/api/my/rotations' && req.method === 'POST') {
const s = await auth.fromRequest(req); if (!s || !s.email) return json(res, 401, { error: 'Sign in first.' });
{ const t = await toolTier(s.email); const have = (await rotator.list(s.email)).length; if (have >= t.max) return json(res, 400, { error: toolCapError('spin links', have, t), tier: t }); }
const r = await rotator.create(s.email, await readBody(req)); return json(res, r.error ? 400 : 200, r);
{ const t = await toolTier(s.email); const have = (await rotator.list(s.email)).filter(x => !x.kind).length; if (have >= t.max) return json(res, 400, { error: toolCapError('spin links', have, t), tier: t }); }
{ const b0 = await readBody(req); const r = await rotator.create(s.email, { name: b0.name, fallback: b0.fallback }); return json(res, r.error ? 400 : 200, r); } // only name and fallback are taken from the member
}
m = /^\/api\/my\/rotations\/(\d+)$/.exec(p);
if (m && req.method === 'POST') {
@@ -2819,12 +2890,15 @@ const server = http.createServer(async (req, res) => {
m = /^\/api\/my\/rotations\/(\d+)\/dest$/.exec(p);
if (m && req.method === 'POST') {
const s = await auth.fromRequest(req); if (!s || !s.email) return json(res, 401, { error: 'Sign in first.' });
if ((await rotator.list(s.email)).some(x => x.id === Number(m[1]) && x.kind === 'video')) return json(res, 400, { error: 'Add videos to a Video Spin from its own screen.' });
const r = await rotator.addDest(s.email, m[1], await readBody(req)); return json(res, r.error ? 400 : 200, r);
}
m = /^\/api\/my\/rotations\/(\d+)\/dest\/(\d+)$/.exec(p);
if (m && req.method === 'POST') {
const s = await auth.fromRequest(req); if (!s || !s.email) return json(res, 401, { error: 'Sign in first.' });
const r = await rotator.updateDest(s.email, m[1], m[2], await readBody(req)); return json(res, r.error ? 400 : 200, r);
const db0 = await readBody(req);
if (db0 && db0.url != null && (await rotator.list(s.email)).some(x => x.id === Number(m[1]) && x.kind === 'video')) return json(res, 400, { error: 'A video in a Video Spin keeps its own address. Remove it and add another instead.' });
const r = await rotator.updateDest(s.email, m[1], m[2], db0); return json(res, r.error ? 400 : 200, r);
}
m = /^\/api\/my\/rotations\/(\d+)\/stats$/.exec(p);
if (m && req.method === 'GET') {