diff --git a/src/services/channels.js b/src/services/channels.js index 96b49e7..5c1355a 100644 --- a/src/services/channels.js +++ b/src/services/channels.js @@ -47,18 +47,42 @@ async function createChannel(userId, data) { if (!name) throw new Error('name is required'); - const client = await require('../config/db').query; + // Загружаем контентные дефолты + const settingsSvc = require('./settings'); + const [ + defLanguage, defLength, defStyle, defGoal, + defImageEnabled, defEmojiEnabled, defHashtags, + defDraftCount, defDraftTime, defStylePrompt, + ] = await Promise.all([ + settingsSvc.get('DEFAULT_POST_LANGUAGE', 'ru'), + settingsSvc.get('DEFAULT_POST_LENGTH', 'medium'), + settingsSvc.get('DEFAULT_POST_STYLE', 'informative'), + settingsSvc.get('DEFAULT_POST_GOAL', 'educational'), + settingsSvc.get('DEFAULT_IMAGE_ENABLED', 'true'), + settingsSvc.get('DEFAULT_EMOJI_ENABLED', 'true'), + settingsSvc.get('DEFAULT_HASHTAGS_IN_POST', 'false'), + settingsSvc.get('DEFAULT_AUTO_DRAFT_COUNT', '3'), + settingsSvc.get('DEFAULT_AUTO_DRAFT_TIME', '08:00'), + settingsSvc.get('DEFAULT_AI_STYLE_PROMPT', ''), + ]); - // INSERT channel + // INSERT channel с дефолтами из системных настроек const { rows: chRows } = await query( `INSERT INTO channels - (user_id, name, tg_channel_id, tg_username, bot_token, niche, audience, goal, language, region) - VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10) + (user_id, name, tg_channel_id, tg_username, bot_token, niche, audience, goal, language, region, + image_enabled, ai_style_prompt, auto_draft_count, auto_draft_time) + VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14) RETURNING *`, [ userId, name, tg_channel_id || null, tg_username || null, bot_token || null, - niche || null, audience || null, goal || 'educational', - language || 'ru', region || 'ru', + niche || null, audience || null, + goal || defGoal, + language || defLanguage, + region || 'ru', + defImageEnabled === 'true', + defStylePrompt || null, + parseInt(defDraftCount) || 3, + defDraftTime || '08:00', ] ); const channel = chRows[0]; @@ -75,9 +99,9 @@ async function createChannel(userId, data) { style.tone_custom || null, style.formality || 'informal', style.humor || 'moderate', - style.post_length || 'medium', + style.post_length || defLength, style.structure || 'mixed', - style.emoji_level || 'moderate', + style.emoji_level || (defEmojiEnabled === 'true' ? 'moderate' : 'none'), style.hashtags_mode || 'end', style.cta_mode || 'sometimes', JSON.stringify(style.example_posts || []),