fix: post thumbnail from linked design artefact, not old PostAttachments
Deploy / deploy (push) Successful in 12s
Deploy / deploy (push) Successful in 12s
- Post.thumbnail_url now synced from linked design artefact's first attachment - syncPostThumbnail() called on: artefact attachment upload, artefact link/unlink - Removed old PostAttachments-based thumbMap from GET /posts and GET /campaigns/:id/posts - Added thumbnail_url to Posts TEXT_COLUMNS - Caption link picker filters by copy_type='caption', body by copy_type='body' Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -96,4 +96,31 @@ function computeStage(composition) {
|
||||
return 'copy';
|
||||
}
|
||||
|
||||
module.exports = { getPostComposition, computeStage };
|
||||
// Sync the post's thumbnail_url from its linked design artefact
|
||||
async function syncPostThumbnail(postId) {
|
||||
try {
|
||||
const artefacts = await nocodb.list('Artefacts', {
|
||||
where: `(post_id,eq,${postId})`, limit: 100,
|
||||
});
|
||||
const design = artefacts.find(a => (a.type || 'design') === 'design');
|
||||
let thumb = null;
|
||||
if (design) {
|
||||
thumb = design.thumbnail_url || null;
|
||||
if (!thumb) {
|
||||
const versions = await nocodb.list('ArtefactVersions', { where: `(artefact_id,eq,${design.Id})`, sort: '-version_number', limit: 1 });
|
||||
if (versions.length > 0) {
|
||||
const attachments = await nocodb.list('ArtefactAttachments', { where: `(version_id,eq,${versions[0].Id})`, limit: 1 });
|
||||
if (attachments.length > 0) {
|
||||
const att = attachments[0];
|
||||
thumb = att.drive_url || (att.filename ? `/api/uploads/${att.filename}` : null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
await nocodb.update('Posts', Number(postId), { thumbnail_url: thumb || null });
|
||||
} catch (e) {
|
||||
console.error('syncPostThumbnail error:', e);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { getPostComposition, computeStage, syncPostThumbnail };
|
||||
|
||||
Reference in New Issue
Block a user