feat: post drafts system — batch generation + daily auto-drafts

DB: post_drafts(channel_id, topic, text, image_url, status), channels.auto_draft_*
Engine:
  services/draftService.js: generateOneDraft, generateBatch, generateDailyDrafts,
    approveDraft(→scheduled_post), rejectDraft, updateDraft, listDrafts
  routes/drafts.js: GET/PATCH/DELETE /api/drafts/:id, /approve, /reject
    POST /api/channels/:channelId/drafts/generate?count=N (async, returns immediately)
  index.js: cron каждые 30 мин → generateDailyDrafts() для каналов с auto_draft_enabled
  channels.js: updateChannel сохраняет auto_draft_enabled/count/time
This commit is contained in:
Ник (Claude)
2026-06-12 23:47:27 +03:00
parent 5a765d27e1
commit a8ff295faa
4 changed files with 340 additions and 2 deletions
+2 -1
View File
@@ -116,7 +116,8 @@ async function updateChannel(channelId, userId, data) {
if (Object.keys(channelFields).length) {
const fields = ['name', 'tg_channel_id', 'tg_username', 'bot_token',
'niche', 'audience', 'goal', 'language', 'region', 'is_active',
'vk_access_token', 'ai_style_prompt', 'image_quality'];
'vk_access_token', 'ai_style_prompt', 'image_quality',
'auto_draft_enabled', 'auto_draft_count', 'auto_draft_time'];
const updates = fields.filter(f => channelFields[f] !== undefined);
if (updates.length) {
const setClauses = updates.map((f, i) => `${f}=$${i + 1}`).join(', ');