feat: POST /api/articles/:id/regenerate-cover for any status

This commit is contained in:
Nik (Claude)
2026-06-16 22:02:34 +03:00
parent d9cbbc5fbf
commit e5965e2804
+25
View File
@@ -204,3 +204,28 @@ router.get('/:slug', async (req, res) => {
}); });
module.exports = router; module.exports = router;
// POST /api/articles/:id/regenerate-cover — перегенерация обложки для любой статьи
router.post('/:id/regenerate-cover', async (req, res) => {
try {
const id = parseInt(req.params.id);
const { rows } = await query('SELECT id, title, tags FROM articles WHERE id=$1', [id]);
if (!rows.length) return res.status(404).json({ error: 'Article not found' });
await query('UPDATE articles SET cover_url=NULL WHERE id=$1', [id]);
const covers = require('../services/covers');
const art = rows[0];
const coverUrl = await covers.generateCover({
articleId: id,
title: art.title,
tags: art.tags || [],
channelId: 1,
});
if (coverUrl) await query('UPDATE articles SET cover_url=$1 WHERE id=$2', [coverUrl, id]);
res.json({ ok: true, cover_url: coverUrl });
} catch (err) {
res.status(500).json({ error: err.message });
}
});