openvibers/openvibe.network Commits

Feed: a card titled with a file name or a bare code leads with its text instead (#1226)

OP OpenVibers committed 7 h ago · 42314051c7 · 3 files, +67 −17

* Feed: a card titled with a file name or a bare code leads with its text instead

Plan §I.2 (the owner, 11-13: a post titled "1000012166"). On the one write path (store.upsertItem, events and polled
sources alike) a title that is only a file name or a code (IMG_2041.jpg, PXL_…mp4, 1000012166, 22845-00) becomes the
start of the card's text (cut at a word, 80 characters), or a plain line for its kind (A picture, A video, A new
thread; a deal names its store). Real titles are kept, numbers and all (2026 recap, Top 10 robots, 1999, 42).
Production, last 30 days: 4 such cards (3 Deals offers, the Community thread). Test: feed-readable-titles; feed,
feed-sources, feed-actor-price and avatar unchanged.

* Dependencies: today's advisories (cross-spawn critical; body-parser, undici high; fast-uri moderate)

npm audit fix on the lockfile: body-parser 1.20.9, cross-spawn 7.0.x fixed, fast-uri 3.1.9, undici 6.29.1, qs 6.15.4
(two moderate qs advisories remain: their fix is a major version). The audit gate fails at critical.

Changes

ddiff --git a/package-lock.json b/package-lock.json
iindex ad5f7774..17e48602 100644
---- a/package-lock.json
++++ b/package-lock.json
@@@ -1198,9 +1198,9 @@
"license": "MIT"
},
"node_modules/body-parser": {
-- "version": "1.20.6",
-- "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.6.tgz",
-- "integrity": "sha512-p5tAzS57i5MV9fZFDj9LeIiTZEufbSe2eDozP+ElheSUq1m74CRq1jI4mYNDdVs9vQztXFLuk/Gd6BWTdwRJ5g==",
++ "version": "1.20.9",
++ "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.9.tgz",
++ "integrity": "sha512-FISIQxV5u91Y9gvuFq3q/tA/qTqLJn3AhRcEvyozyhJTh5OBFFtv827AdHU7Rbyct4r+Ba1/99oFa1Y3yuFsdw==",
"license": "MIT",
"dependencies": {
"bytes": "~3.1.2",
@@@ -1211,7 +1211,7 @@
"http-errors": "~2.0.1",
"iconv-lite": "~0.4.24",
"on-finished": "~2.4.1",
-- "qs": "~6.15.1",
++ "qs": "~6.16.0",
"raw-body": "~2.5.3",
"type-is": "~1.6.18",
"unpipe": "~1.0.0"
@@@ -1221,6 +1221,22 @@
"npm": "1.2.8000 || >= 1.4.16"
}
},
++ "node_modules/body-parser/node_modules/qs": {
++ "version": "6.16.2",
++ "resolved": "https://registry.npmjs.org/qs/-/qs-6.16.2.tgz",
++ "integrity": "sha512-VYdnB5S7/0IeXzBacUtwNAaM6d7Y/PgYnNC7bJCI6meqA/OgnsQbZMtVW8Dt2D1PHgbHGtYmhSoEIgvt7xZ2ZA==",
++ "license": "BSD-3-Clause",
++ "dependencies": {
++ "es-define-property": "^1.0.1",
++ "side-channel": "^1.1.1"
++ },
++ "engines": {
++ "node": ">=0.6"
++ },
++ "funding": {
++ "url": "https://github.com/sponsors/ljharb"
++ }
++ },
"node_modules/boolbase": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/boolbase/-/boolbase-2.0.0.tgz",
@@@ -1448,9 +1464,9 @@
}
},
"node_modules/cross-spawn": {
-- "version": "7.0.6",
-- "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz",
-- "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==",
++ "version": "7.1.2",
++ "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.1.2.tgz",
++ "integrity": "sha512-8BPK2r+sKWC8sDinRwLwrFMq2lXTBBwzYYEB9LiCznfMurOi4FOvQflq3XOLGG+HPdMSVpe+k/s96+AtDEOgPg==",
"dev": true,
"license": "MIT",
"dependencies": {
@@@ -1854,9 +1870,9 @@
"license": "MIT"
},
"node_modules/fast-uri": {
-- "version": "3.1.8",
-- "resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-3.1.8.tgz",
-- "integrity": "sha512-GZMtZUTNRpOVIECoXwLNZS5xUGE+mVNbTB8h/7Rwh2TFWcBQiPzTgyZi05BF9UMZKkLJv8XBRJTlU7zg8+ZfMg==",
++ "version": "3.1.9",
++ "resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-3.1.9.tgz",
++ "integrity": "sha512-hS/0Wt3Ya043oKXs0sIxrMpKQITXhMLIrVAKKXi4gozGC9v7YRWVnXIZzjNPTO02M9BdxLCWqK1yRXgNziVyJQ==",
"funding": [
{
"type": "github",
@@@ -3027,9 +3043,9 @@
}
},
"node_modules/qs": {
-- "version": "6.15.3",
-- "resolved": "https://registry.npmjs.org/qs/-/qs-6.15.3.tgz",
-- "integrity": "sha512-O9gl3zCl5h5blw1KGUzQKhA5oUXSl8rwUIM5o0S3nCXMliSvy5Dzx7/DJcI+SwgICv+IneSZwhBh1oSyEHA71A==",
++ "version": "6.15.4",
++ "resolved": "https://registry.npmjs.org/qs/-/qs-6.15.4.tgz",
++ "integrity": "sha512-d1zNHS+ltAfSgTmYjzXXH9gy9d6pEb33n0ZtUUkukA8UHhFSjv2mSYRiePyjbRiJh0g5sFJbMdAtMIg01Xf5/w==",
"license": "BSD-3-Clause",
"dependencies": {
"es-define-property": "^1.0.1",
@@@ -3556,9 +3572,9 @@
"license": "ISC"
},
"node_modules/undici": {
-- "version": "6.28.0",
-- "resolved": "https://registry.npmjs.org/undici/-/undici-6.28.0.tgz",
-- "integrity": "sha512-LIY910g9TI13YS95lrMFrs8Rm/u/irgHeTWoKCoteeJ04CUJ92eEfj0rVn+7VKMPBpUPiUoBKfhNyLI23EE/KA==",
++ "version": "6.29.1",
++ "resolved": "https://registry.npmjs.org/undici/-/undici-6.29.1.tgz",
++ "integrity": "sha512-EvRlUt/QqAEvXdQeRMYUfwOQsfzpDztykrG2owGEE/rBOBoYv9uF39ZzsNDh4lTFHhTr2XOZjKkYgueD12ZmGA==",
"license": "MIT",
"engines": {
"node": ">=18.17"
ddiff --git a/server/feed/store.js b/server/feed/store.js
iindex 46fe9247..2b289f02 100644
---- a/server/feed/store.js
++++ b/server/feed/store.js
@@@ -40,7 +40,21 @@ const countsJson = (v) => {
};
/** → { item, created } */
++// A title that is only a file name or a bare code ("1000012166", "IMG_2041.jpg", "22845-00") says nothing on a card
++// (plan §I.2, the owner 11-13). The card leads with the start of its text instead, or a plain line for its kind.
++const FILE_TITLE = /^(?:(?:img|vid|pxl|dsc|dscn|screenshot|photo|video|image|mvimg|signal|wp)[-_ ]?)?[0-9][0-9_ .-]{4,}(?:\.[a-z0-9]{2,4})?$|\.(?:jpe?g|png|gif|webp|mp4|mov|heic|webm|avif)$/i;
++const KIND_TITLE = { deal: 'A deal', video: 'A video', picture: 'A picture', photo: 'A picture', post: 'A post', thread: 'A new thread', clip: 'A clip' };
++function readableTitle(it) {
++ const title = String(it.title || '').trim();
++ if (!title || !FILE_TITLE.test(title)) return it.title;
++ const text = String(it.text || '').replace(/\s+/g, ' ').trim();
++ if (text && !FILE_TITLE.test(text)) return text.length > 80 ? `${text.slice(0, 79).replace(/\s+\S*$/, '')}…` : text;
++ if (it.kind === 'deal' && it.store_name) return `A deal at ${String(it.store_name).slice(0, 60)}`;
++ return KIND_TITLE[it.kind] || 'A new post';
++}
++
async function upsertItem(db, it) {
++ it = { ...it, title: readableTitle(it) };
const at = iso(it.occurred_at) || new Date().toISOString();
const key = [it.source_service, it.source_type, String(it.source_id)];
const find = db.prepare(`SELECT ${COLUMNS} FROM feed_items WHERE source_service = ? AND source_type = ? AND source_id = ?`);
@@@ -267,4 +281,4 @@ async function burstStart(db, { kind, site, before }) {
return other ? null : iso(first.at);
}
--module.exports = { isItemDiscussionUrl, upsertItem, upsertLiveItem, removeItem, removeMissing, followedSubjects, affinityServices, listItems, listRuns, runRows, RUN_KINDS, countBulk, burstStart, iso, ms };
++module.exports = { readableTitle, isItemDiscussionUrl, upsertItem, upsertLiveItem, removeItem, removeMissing, followedSubjects, affinityServices, listItems, listRuns, runRows, RUN_KINDS, countBulk, burstStart, iso, ms };
ddiff --git a/test/feed-readable-titles.test.js b/test/feed-readable-titles.test.js
nnew file mode 100644
iindex 00000000..3b83708d
---- /dev/null
++++ b/test/feed-readable-titles.test.js
@@@ -0,0 +1,20 @@
++'use strict';
++// A feed card's title that is only a file name or a bare code ("1000012166" on a Community thread, "22845-00" on a deal)
++// says nothing (plan §I.2, the owner 11-13): the card leads with the start of its text instead, or a plain line for its
++// kind (a deal names its store). A real title, numbers and all, is kept.
++const assert = require('assert');
++const { readableTitle } = require('../server/feed/store');
++
++const t = (title, kind, extra = {}) => readableTitle({ title, kind, ...extra });
++
++assert.strictEqual(t('1000012166', 'post', { text: 'Lentil soup tonight, recipe inside' }), 'Lentil soup tonight, recipe inside');
++assert.strictEqual(t('IMG_2041.jpg', 'picture'), 'A picture');
++assert.strictEqual(t('PXL_20261130_224512345.mp4', 'video'), 'A video');
++assert.strictEqual(t('22845-00', 'deal', { store_name: 'Best Buy' }), 'A deal at Best Buy');
++assert.strictEqual(t('1364409-465', 'deal'), 'A deal');
++assert.strictEqual(t('1000012166', 'thread', { text: '1000012166.jpg' }), 'A new thread', 'a text that is a file name too is no better');
++const long = t('20261130_101010', 'post', { text: 'A very long first line about the robot driving into the kitchen and then all the way back out again past the fridge' });
++assert.ok(long.length <= 80 && long.endsWith('…') && !/\s…$/.test(long), `cut at a word: ${long}`);
++for (const kept of ['Lentil Soup', '2026 recap', 'Top 10 robots', '1999', 'GTA 6 trailer', '42']) assert.strictEqual(t(kept, 'post'), kept, kept);
++assert.strictEqual(t('', 'post'), '', 'no title stays no title (the card has its own fallback)');
++console.log('feed-readable-titles: file names and bare codes become the text or a plain line; real titles kept');