fix: #9130, remove timestamp prefix from thumbnail names in API response

v1.18.x
Julian Lam 4 years ago
parent 8c31afae7d
commit 171017c38c

@ -31,12 +31,16 @@ Thumbs.get = async function (tids) {
return singular ? null : tids.map(() => []); return singular ? null : tids.map(() => []);
} }
const hasTimestampPrefix = /^\d+-/;
const upload_url = nconf.get('upload_url'); const upload_url = nconf.get('upload_url');
const sets = tids.map(tid => `${validator.isUUID(String(tid)) ? 'draft' : 'topic'}:${tid}:thumbs`); const sets = tids.map(tid => `${validator.isUUID(String(tid)) ? 'draft' : 'topic'}:${tid}:thumbs`);
const thumbs = await Promise.all(sets.map(set => getThumbs(set))); const thumbs = await Promise.all(sets.map(set => getThumbs(set)));
let response = thumbs.map((thumbSet, idx) => thumbSet.map(thumb => ({ let response = thumbs.map((thumbSet, idx) => thumbSet.map(thumb => ({
id: tids[idx], id: tids[idx],
name: path.basename(thumb), name: (() => {
const name = path.basename(thumb);
return hasTimestampPrefix.test(name) ? name.slice(14) : name;
})(),
url: thumb.startsWith('http') ? thumb : path.posix.join(upload_url, thumb), url: thumb.startsWith('http') ? thumb : path.posix.join(upload_url, thumb),
}))); })));

Loading…
Cancel
Save