openvibers/openvibe.network Commits
Feed: a card titled with a file name or a bare code leads with its text instead (#1226)
Changes
@@@ -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"@@@ -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 };nnew file mode 100644@@@ -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');
@@ -1198,9 +1198,9 @@
@@ -1198,9 +1198,9 @@
"license": "MIT"
"license": "MIT"
},
},
"node_modules/body-parser": {
"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",
"license": "MIT",
"dependencies": {
"dependencies": {
"bytes": "~3.1.2",
"bytes": "~3.1.2",
@@ -1211,7 +1211,7 @@
@@ -1211,7 +1211,7 @@
"http-errors": "~2.0.1",
"http-errors": "~2.0.1",
"iconv-lite": "~0.4.24",
"iconv-lite": "~0.4.24",
"on-finished": "~2.4.1",
"on-finished": "~2.4.1",
- "qs": "~6.15.1",
+ "qs": "~6.16.0",
"raw-body": "~2.5.3",
"raw-body": "~2.5.3",
"type-is": "~1.6.18",
"type-is": "~1.6.18",
"unpipe": "~1.0.0"
"unpipe": "~1.0.0"
@@ -1221,6 +1221,22 @@
@@ -1221,6 +1221,22 @@
"npm": "1.2.8000 || >= 1.4.16"
"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": {
"node_modules/boolbase": {
"version": "2.0.0",
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/boolbase/-/boolbase-2.0.0.tgz",
"resolved": "https://registry.npmjs.org/boolbase/-/boolbase-2.0.0.tgz",
@@ -1448,9 +1464,9 @@
@@ -1448,9 +1464,9 @@
}
}
},
},
"node_modules/cross-spawn": {
"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,
"dev": true,
"license": "MIT",
"license": "MIT",
"dependencies": {
"dependencies": {
@@ -1854,9 +1870,9 @@
@@ -1854,9 +1870,9 @@
"license": "MIT"
"license": "MIT"
},
},
"node_modules/fast-uri": {
"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": [
"funding": [
{
{
"type": "github",
"type": "github",
@@ -3027,9 +3043,9 @@
@@ -3027,9 +3043,9 @@
}
}
},
},
"node_modules/qs": {
"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",
"license": "BSD-3-Clause",
"dependencies": {
"dependencies": {
"es-define-property": "^1.0.1",
"es-define-property": "^1.0.1",
@@ -3556,9 +3572,9 @@
@@ -3556,9 +3572,9 @@
"license": "ISC"
"license": "ISC"
},
},
"node_modules/undici": {
"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",
"license": "MIT",
"engines": {
"engines": {
"node": ">=18.17"
"node": ">=18.17"
@@ -40,7 +40,21 @@ const countsJson = (v) => {
@@ -40,7 +40,21 @@ const countsJson = (v) => {
};
};
/** → { item, created } */
/** → { 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) {
async function upsertItem(db, it) {
+ it = { ...it, title: readableTitle(it) };
const at = iso(it.occurred_at) || new Date().toISOString();
const at = iso(it.occurred_at) || new Date().toISOString();
const key = [it.source_service, it.source_type, String(it.source_id)];
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 = ?`);
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 }) {
@@ -267,4 +281,4 @@ async function burstStart(db, { kind, site, before }) {
return other ? null : iso(first.at);
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 };
new file mode 100644
new file mode 100644
@@ -0,0 +1,20 @@
@@ -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');