feat: POST /api/articles/:id/regenerate-cover for any status
This commit is contained in:
@@ -204,3 +204,28 @@ router.get('/:slug', async (req, res) => {
|
||||
});
|
||||
|
||||
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 });
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user