openvibers/openvibe.live Commits

AI moment pastes name the streamer: Media's VOD list gives only the owner's id, so the footer read '@null's stream' (478 pastes) (#305)

OP OpenVibers committed 22 days ago · 5609ced7cd · 2 files, +8 −2

Changes

ddiff --git a/server/ai/ai-moments-job.js b/server/ai/ai-moments-job.js
iindex c82e68d8..225e9bf7 100644
---- a/server/ai/ai-moments-job.js
++++ b/server/ai/ai-moments-job.js
@@@ -269,6 +269,10 @@ async function _momentPool(limit) {
if (rows.length) {
return (await Promise.all(rows.map(async (v) => {
const state = (db.getVodAiState && await db.getVodAiState(v.id)) || {};
++ // Media's list names the owner by id only: the moment's footer and title name them by username
++ // (pastes read "@null's stream" without it).
++ let username = v.username || null;
++ if (!username && v.user_id) { try { username = (await db.getUserById(v.user_id))?.username || null; } catch { /* */ } }
let memory_count = 0, peak_viewers = 0;
if (v.stream_id) {
try { memory_count = (await db.get('SELECT COUNT(*) AS c FROM stream_memories WHERE stream_id = ?', [v.stream_id]))?.c || 0; } catch { /* */ }
@@@ -276,7 +280,7 @@ async function _momentPool(limit) {
}
return {
vod_id: v.id, stream_id: v.stream_id || null, user_id: v.user_id || null,
-- username: v.username || null, title: v.title || '',
++ username, title: v.title || '',
ai_overview: state.ai_overview_short || v.ai_overview_short || '',
ai_overview_short: state.ai_overview_short || v.ai_overview_short || '',
view_count: Number(v.view_count) || 0,
@@@ -422,7 +426,7 @@ async function tick(opts = {}) {
continue;
}
if (finalSig) thisSigs.add(finalSig);
-- const content = `${desc}\n\n▶ Watch this moment on @${v.username}'s stream: ${vodLink}`;
++ const content = `${desc}\n\n▶ Watch this moment on ${v.username ? `@${v.username}'s stream` : 'the stream'}: ${vodLink}`;
const metadata = JSON.stringify({ ai_moment: true, vod_id: v.vod_id, offset, vod_link: vodPath, username: v.username, why: r.why || null });
let pasteSlug = slug;
try {
ddiff --git a/test/ai-derivation-optout.test.js b/test/ai-derivation-optout.test.js
iindex 14288ef8..848e854c 100644
---- a/test/ai-derivation-optout.test.js
++++ b/test/ai-derivation-optout.test.js
@@@ -160,6 +160,8 @@ async function check(name, fn) {
await check("the AI moments job never picks an opted-out channel's VODs", async () => {
const pool = await moments._internals.momentPool(10);
assert.deepStrictEqual(pool.map((v) => v.vod_id), [10]);
++ // Media's list names the owner by id only: the pool names them by username (pastes read "@null's stream").
++ assert.strictEqual(pool[0].username, 'alice');
});
await check('no "caught live" paste from an opted-out stream', async () => {