feat: transformPost (7 actions), post image generation with style/palette, topics ideas endpoint

This commit is contained in:
Alexey Pavlov
2026-05-31 17:32:38 +03:00
parent 53d596ca2e
commit 2137a92b28
3 changed files with 229 additions and 0 deletions
+69
View File
@@ -42,4 +42,73 @@ router.get('/:id', async (req, res) => {
}
});
// POST /api/generate/transform — синхронная трансформация поста (короче/длиннее/улучшить)
router.post('/transform', async (req, res) => {
try {
const { channelId, originalPost, action } = req.body;
const userId = parseInt(req.headers['x-user-id']) || null;
if (!channelId || !originalPost || !action) {
return res.status(400).json({ error: 'channelId, originalPost, action required' });
}
const channel = await channelsSvc.getChannel(userId, channelId);
if (!channel) return res.status(404).json({ error: 'Channel not found' });
const ai = require('../services/ai');
const result = await ai.transformPost(channel, { originalPost, action });
res.json(result);
} catch (err) {
console.error('[Route] POST /transform', err);
res.status(500).json({ error: err.message });
}
});
// POST /api/generate/post-image — синхронная генерация картинки к посту
router.post('/post-image', async (req, res) => {
try {
const { channelId, post } = req.body;
const userId = parseInt(req.headers['x-user-id']) || null;
if (!channelId || !post) return res.status(400).json({ error: 'channelId and post required' });
const channel = await channelsSvc.getChannel(userId, channelId);
if (!channel) return res.status(404).json({ error: 'Channel not found' });
const { generatePostImage } = require('../services/postImages');
const result = await generatePostImage({ post, channel, style: channel.style || {} });
res.json(result);
} catch (err) {
console.error('[Route] POST /post-image', err);
res.status(500).json({ error: err.message });
}
});
// GET /api/generate/image-styles — список доступных стилей картинок
router.get('/image-styles', async (_, res) => {
const { IMAGE_STYLES, IMAGE_PALETTES } = require('../services/postImages');
res.json({
styles: Object.entries(IMAGE_STYLES).map(([v, s]) => ({ value: v, label: s.label })),
palettes: Object.keys(IMAGE_PALETTES).map(v => ({
value: v,
label: { auto: 'Авто', dark: 'Тёмная', light: 'Светлая', warm: 'Тёплая', cool: 'Холодная', mono: 'Монохром', vibrant: 'Яркая' }[v] || v
})),
});
});
// POST /api/generate/topics-ideas — синхронные идеи тем для канала
router.post('/topics-ideas', async (req, res) => {
try {
const { channelId, count = 7 } = req.body;
const userId = parseInt(req.headers['x-user-id']) || null;
if (!channelId) return res.status(400).json({ error: 'channelId required' });
const channel = await channelsSvc.getChannel(userId, channelId);
if (!channel) return res.status(404).json({ error: 'Channel not found' });
const ai = require('../services/ai');
const result = await ai.generateTopics(channel, count);
res.json(result);
} catch (err) {
console.error('[Route] POST /topics-ideas', err);
res.status(500).json({ error: err.message });
}
});
module.exports = router;