feat: initial zeropost-engine structure

- AI service with Anthropic claude-sonnet-4-6
- Bull queue for async generation jobs
- Routes: /api/generate, /api/channels, /api/posts
- PostgreSQL schema: users, channels, posts, generation_jobs
- Supports: post, article, topics generation types
This commit is contained in:
Alexey Pavlov
2026-05-30 21:29:00 +03:00
parent 1b9767f269
commit 612053b93d
12 changed files with 1907 additions and 0 deletions
+50
View File
@@ -0,0 +1,50 @@
const express = require('express');
const router = express.Router();
const { query } = require('../config/db');
// GET /api/channels - list channels for user
router.get('/', async (req, res) => {
const userId = req.headers['x-user-id'];
if (!userId) return res.status(401).json({ error: 'Unauthorized' });
const { rows } = await query(`SELECT * FROM channels WHERE user_id=$1 ORDER BY created_at DESC`, [userId]);
res.json(rows);
});
// POST /api/channels - create channel
router.post('/', async (req, res) => {
const userId = req.headers['x-user-id'];
if (!userId) return res.status(401).json({ error: 'Unauthorized' });
const { name, tgChannelId, botToken, topic, tone, language } = req.body;
if (!name) return res.status(400).json({ error: 'name is required' });
const { rows } = await query(
`INSERT INTO channels (user_id, name, tg_channel_id, bot_token, topic, tone, language) VALUES ($1,$2,$3,$4,$5,$6,$7) RETURNING *`,
[userId, name, tgChannelId || null, botToken || null, topic || '', tone || 'neutral', language || 'ru']
);
res.json(rows[0]);
});
// PATCH /api/channels/:id - update channel
router.patch('/:id', async (req, res) => {
const userId = req.headers['x-user-id'];
const { name, topic, tone, language, botToken, tgChannelId, isActive, postSchedule } = req.body;
const { rows } = await query(
`UPDATE channels SET
name=COALESCE($1,name), topic=COALESCE($2,topic), tone=COALESCE($3,tone),
language=COALESCE($4,language), bot_token=COALESCE($5,bot_token),
tg_channel_id=COALESCE($6,tg_channel_id), is_active=COALESCE($7,is_active),
post_schedule=COALESCE($8,post_schedule)
WHERE id=$9 AND user_id=$10 RETURNING *`,
[name, topic, tone, language, botToken, tgChannelId, isActive, postSchedule ? JSON.stringify(postSchedule) : null, req.params.id, userId]
);
if (!rows.length) return res.status(404).json({ error: 'Channel not found' });
res.json(rows[0]);
});
// DELETE /api/channels/:id
router.delete('/:id', async (req, res) => {
const userId = req.headers['x-user-id'];
await query(`DELETE FROM channels WHERE id=$1 AND user_id=$2`, [req.params.id, userId]);
res.json({ ok: true });
});
module.exports = router;