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
+40
View File
@@ -0,0 +1,40 @@
const express = require('express');
const router = express.Router();
const { query } = require('../config/db');
const generationQueue = require('../workers/generation');
// POST /api/generate - create generation job
router.post('/', async (req, res) => {
try {
const { type, topic, tone = 'neutral', language = 'ru', channelContext = '', keywords = [], channelId } = req.body;
if (!type || !topic) return res.status(400).json({ error: 'type and topic are required' });
if (!['post', 'article', 'topics'].includes(type)) return res.status(400).json({ error: 'Invalid type' });
const { rows } = await query(
`INSERT INTO generation_jobs (type, channel_id, topic, status) VALUES ($1,$2,$3,'pending') RETURNING id`,
[type, channelId || null, topic]
);
const jobId = rows[0].id;
await generationQueue.add({ jobId, type, topic, tone, language, channelContext, keywords });
res.json({ jobId, status: 'pending' });
} catch (err) {
console.error('[Route] POST /generate', err);
res.status(500).json({ error: err.message });
}
});
// GET /api/generate/:id - get job status
router.get('/:id', async (req, res) => {
try {
const { rows } = await query(`SELECT * FROM generation_jobs WHERE id=$1`, [req.params.id]);
if (!rows.length) return res.status(404).json({ error: 'Job not found' });
res.json(rows[0]);
} catch (err) {
res.status(500).json({ error: err.message });
}
});
module.exports = router;