feat(autogen/queue): queue = черновики сегодня (планируется завтра)

This commit is contained in:
Aleksei Pavlov
2026-06-21 21:17:09 +03:00
parent f40bb27953
commit 630287f02f
+24 -11
View File
@@ -40,33 +40,46 @@ router.patch('/settings/:category', async (req, res) => {
}); });
// GET /api/autogen/queue — очередь тем // GET /api/autogen/queue — очередь тем
// GET /api/autogen/queue — черновики созданные сегодня (планируется завтра)
router.get('/queue', async (_, res) => { router.get('/queue', async (_, res) => {
try { try {
const { rows } = await query( const { rows } = await query(`
`SELECT * FROM content_queue ORDER BY priority DESC, created_at ASC LIMIT 100` SELECT a.id, a.category, a.status, a.title, a.cover_url,
); a.created_at, a.published_at,
c.name AS cat_name, c.icon AS cat_icon, c.color AS cat_color
FROM articles a
LEFT JOIN categories c ON c.slug = a.category
WHERE a.status = 'draft'
AND a.created_at >= CURRENT_DATE
ORDER BY a.category, a.created_at DESC
`);
res.json(rows); res.json(rows);
} catch (err) { res.status(500).json({ error: err.message }); } } catch (err) { res.status(500).json({ error: err.message }); }
}); });
// POST /api/autogen/queue — добавить тему в очередь // POST /api/autogen/queue — добавить тему в blog_topics (быстрый приоритет p9)
router.post('/queue', async (req, res) => { router.post('/queue', async (req, res) => {
try { try {
const { category, topic, tags = [], keywords = [], priority = 5 } = req.body; const { category, topic, priority = 9 } = req.body;
if (!category || !topic) return res.status(400).json({ error: 'category and topic required' }); if (!category || !topic) return res.status(400).json({ error: 'category and topic required' });
const { rows } = await query( const { rows } = await query(
`INSERT INTO content_queue (category, topic, tags, keywords, priority) `INSERT INTO blog_topics (category, topic, source, priority, is_used)
VALUES ($1,$2,$3,$4,$5) RETURNING *`, VALUES ($1,$2,'manual',$3,false) ON CONFLICT DO NOTHING RETURNING *`,
[category, topic, JSON.stringify(tags), JSON.stringify(keywords), priority] [category, topic, priority]
); );
res.json(rows[0]); res.json(rows[0] || { ok: true, note: 'already exists' });
} catch (err) { res.status(500).json({ error: err.message }); } } catch (err) { res.status(500).json({ error: err.message }); }
}); });
// DELETE /api/autogen/queue/:id // DELETE /api/autogen/queue/:id — удалить черновик статьи
router.delete('/queue/:id', async (req, res) => { router.delete('/queue/:id', async (req, res) => {
try { try {
await query(`DELETE FROM content_queue WHERE id=$1`, [req.params.id]); const { rows: [art] } = await query(
`SELECT id FROM articles WHERE id=$1 AND status='draft'`,
[parseInt(req.params.id, 10)]
);
if (!art) return res.status(404).json({ error: 'draft not found' });
await query(`DELETE FROM articles WHERE id=$1 AND status='draft'`, [parseInt(req.params.id, 10)]);
res.json({ ok: true }); res.json({ ok: true });
} catch (err) { res.status(500).json({ error: err.message }); } } catch (err) { res.status(500).json({ error: err.message }); }
}); });