From 630287f02ff10ea4171c71c3435fc6ae2d1bc745 Mon Sep 17 00:00:00 2001 From: Aleksei Pavlov Date: Sun, 21 Jun 2026 21:17:09 +0300 Subject: [PATCH] =?UTF-8?q?feat(autogen/queue):=20queue=20=3D=20=D1=87?= =?UTF-8?q?=D0=B5=D1=80=D0=BD=D0=BE=D0=B2=D0=B8=D0=BA=D0=B8=20=D1=81=D0=B5?= =?UTF-8?q?=D0=B3=D0=BE=D0=B4=D0=BD=D1=8F=20(=D0=BF=D0=BB=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D1=80=D1=83=D0=B5=D1=82=D1=81=D1=8F=20=D0=B7=D0=B0=D0=B2?= =?UTF-8?q?=D1=82=D1=80=D0=B0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/routes/autogen.js | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/src/routes/autogen.js b/src/routes/autogen.js index 483f26c..c2a1292 100644 --- a/src/routes/autogen.js +++ b/src/routes/autogen.js @@ -40,33 +40,46 @@ router.patch('/settings/:category', async (req, res) => { }); // GET /api/autogen/queue — очередь тем +// GET /api/autogen/queue — черновики созданные сегодня (планируется завтра) router.get('/queue', async (_, res) => { try { - const { rows } = await query( - `SELECT * FROM content_queue ORDER BY priority DESC, created_at ASC LIMIT 100` - ); + const { rows } = await query(` + 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); } 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) => { 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' }); const { rows } = await query( - `INSERT INTO content_queue (category, topic, tags, keywords, priority) - VALUES ($1,$2,$3,$4,$5) RETURNING *`, - [category, topic, JSON.stringify(tags), JSON.stringify(keywords), priority] + `INSERT INTO blog_topics (category, topic, source, priority, is_used) + VALUES ($1,$2,'manual',$3,false) ON CONFLICT DO NOTHING RETURNING *`, + [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 }); } }); -// DELETE /api/autogen/queue/:id +// DELETE /api/autogen/queue/:id — удалить черновик статьи router.delete('/queue/:id', async (req, res) => { 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 }); } catch (err) { res.status(500).json({ error: err.message }); } });