openvibers/openvibe.community Commits
The home's latest and most viewed leave out a paste whose title fails openvibe-sdk/front-page; the paste keeps its page and the lists (#132)
Changes
@@@ -38,6 +38,11 @@ function _metaKind(p) {try { return (typeof m === 'string' ? JSON.parse(m) : m).kind || null; } catch { return null; }}const _shared = (rows) => rows.filter((p) => _metaKind(p) !== 'avatar');++// The home's latest and most viewed are the site's front page, read by everyone who arrives: a paste whose title++// carries a slur, strong profanity or a hate topic is left off them (openvibe-sdk/front-page; an anonymous screenshot++// titled with a slur sat in "Most viewed" on 2026-10-24) and the next one shown. The paste keeps its own page.++const { frontPageOk } = require('openvibe-sdk/front-page');++const _front = (rows) => _shared(rows).filter((p) => !String(p.title || '').trim() || frontPageOk(p.title)); // untitled: nothing to judge/** The latest public pastes of one type and origin (cached). Never throws: an unavailable store yields the stale list or []. */async function windowOf({ type = null, from = 'all' } = {}) {@@@ -63,8 +68,8 @@ function byViews(a, b) { return (b.views || 0) - (a.views || 0) || (b.likes || 0function byNewest(a, b) { return String(b.created_at || '').localeCompare(String(a.created_at || '')); }const fromOf = (v) => (Object.prototype.hasOwnProperty.call(FROM, v) ? v : 'all');--async function latest(n = 12, { from = 'all' } = {}) { return _shared(await windowOf({ from: fromOf(from) })).sort(byNewest).slice(0, n); }--async function trending(n = 8, { from = 'all' } = {}) { return _shared(await windowOf({ from: fromOf(from) })).sort(byViews).slice(0, n); }++async function latest(n = 12, { from = 'all' } = {}) { return _front(await windowOf({ from: fromOf(from) })).sort(byNewest).slice(0, n); }++async function trending(n = 8, { from = 'all' } = {}) { return _front(await windowOf({ from: fromOf(from) })).sort(byViews).slice(0, n); }/** Pastes in the same language first, then the newest, never the paste itself. */async function related(paste, n = 6) {@@@ -60,5 +60,12 @@ const check = async (name, fn) => { catalog.reset(); await fn(); passed++; consoassert.strictEqual((await catalog.trending(3))[0].slug, 'shot-198', 'most viewed: the avatar is skipped');assert.strictEqual((await catalog.browse({ type: 'images', sort: 'views' })).pastes[0].slug, 'shot-199', 'the image list still has it');});++ await check('the home\'s latest and most viewed leave a rough title out (openvibe-sdk/front-page); the lists keep it', async () => {++ shots[198].title = 'this is bullshit';++ assert.strictEqual((await catalog.latest(3))[0].slug, 'shot-197', 'latest: the next one shows');++ assert.strictEqual((await catalog.trending(3))[0].slug, 'shot-197', 'most viewed: the next one shows');++ assert.strictEqual((await catalog.browse({ type: 'images', sort: 'views' })).pastes[1].slug, 'shot-198', 'the image list keeps it');++ delete shots[198].title;++ });console.log(`paste catalog: ${passed} checks passed`);})().catch((err) => { console.error(err); process.exit(1); });
@@ -38,6 +38,11 @@ function _metaKind(p) {
@@ -38,6 +38,11 @@ function _metaKind(p) {
try { return (typeof m === 'string' ? JSON.parse(m) : m).kind || null; } catch { return null; }
try { return (typeof m === 'string' ? JSON.parse(m) : m).kind || null; } catch { return null; }
}
}
const _shared = (rows) => rows.filter((p) => _metaKind(p) !== 'avatar');
const _shared = (rows) => rows.filter((p) => _metaKind(p) !== 'avatar');
+// The home's latest and most viewed are the site's front page, read by everyone who arrives: a paste whose title
+// carries a slur, strong profanity or a hate topic is left off them (openvibe-sdk/front-page; an anonymous screenshot
+// titled with a slur sat in "Most viewed" on 2026-10-24) and the next one shown. The paste keeps its own page.
+const { frontPageOk } = require('openvibe-sdk/front-page');
+const _front = (rows) => _shared(rows).filter((p) => !String(p.title || '').trim() || frontPageOk(p.title)); // untitled: nothing to judge
/** The latest public pastes of one type and origin (cached). Never throws: an unavailable store yields the stale list or []. */
/** The latest public pastes of one type and origin (cached). Never throws: an unavailable store yields the stale list or []. */
async function windowOf({ type = null, from = 'all' } = {}) {
async function windowOf({ type = null, from = 'all' } = {}) {
@@ -63,8 +68,8 @@ function byViews(a, b) { return (b.views || 0) - (a.views || 0) || (b.likes || 0
@@ -63,8 +68,8 @@ function byViews(a, b) { return (b.views || 0) - (a.views || 0) || (b.likes || 0
function byNewest(a, b) { return String(b.created_at || '').localeCompare(String(a.created_at || '')); }
function byNewest(a, b) { return String(b.created_at || '').localeCompare(String(a.created_at || '')); }
const fromOf = (v) => (Object.prototype.hasOwnProperty.call(FROM, v) ? v : 'all');
const fromOf = (v) => (Object.prototype.hasOwnProperty.call(FROM, v) ? v : 'all');
-async function latest(n = 12, { from = 'all' } = {}) { return _shared(await windowOf({ from: fromOf(from) })).sort(byNewest).slice(0, n); }
-async function trending(n = 8, { from = 'all' } = {}) { return _shared(await windowOf({ from: fromOf(from) })).sort(byViews).slice(0, n); }
+async function latest(n = 12, { from = 'all' } = {}) { return _front(await windowOf({ from: fromOf(from) })).sort(byNewest).slice(0, n); }
+async function trending(n = 8, { from = 'all' } = {}) { return _front(await windowOf({ from: fromOf(from) })).sort(byViews).slice(0, n); }
/** Pastes in the same language first, then the newest, never the paste itself. */
/** Pastes in the same language first, then the newest, never the paste itself. */
async function related(paste, n = 6) {
async function related(paste, n = 6) {
@@ -60,5 +60,12 @@ const check = async (name, fn) => { catalog.reset(); await fn(); passed++; conso
@@ -60,5 +60,12 @@ const check = async (name, fn) => { catalog.reset(); await fn(); passed++; conso
assert.strictEqual((await catalog.trending(3))[0].slug, 'shot-198', 'most viewed: the avatar is skipped');
assert.strictEqual((await catalog.trending(3))[0].slug, 'shot-198', 'most viewed: the avatar is skipped');
assert.strictEqual((await catalog.browse({ type: 'images', sort: 'views' })).pastes[0].slug, 'shot-199', 'the image list still has it');
assert.strictEqual((await catalog.browse({ type: 'images', sort: 'views' })).pastes[0].slug, 'shot-199', 'the image list still has it');
});
});
+ await check('the home\'s latest and most viewed leave a rough title out (openvibe-sdk/front-page); the lists keep it', async () => {
+ shots[198].title = 'this is bullshit';
+ assert.strictEqual((await catalog.latest(3))[0].slug, 'shot-197', 'latest: the next one shows');
+ assert.strictEqual((await catalog.trending(3))[0].slug, 'shot-197', 'most viewed: the next one shows');
+ assert.strictEqual((await catalog.browse({ type: 'images', sort: 'views' })).pastes[1].slug, 'shot-198', 'the image list keeps it');
+ delete shots[198].title;
+ });
console.log(`paste catalog: ${passed} checks passed`);
console.log(`paste catalog: ${passed} checks passed`);
})().catch((err) => { console.error(err); process.exit(1); });
})().catch((err) => { console.error(err); process.exit(1); });