From 9b40f2cd7a3c1e0ed4f9ea14e630ec461f80a142 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=20=28Claude=29?= Date: Sat, 13 Jun 2026 11:22:08 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20content=20defaults=20=E2=80=94=20applie?= =?UTF-8?q?d=20on=20channel=20creation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit DB: app_settings category=content (10 keys) channels.js: createChannel reads DEFAULT_* from settings and applies to new channel DEFAULT_POST_LANGUAGE/LENGTH/STYLE/GOAL → channel.goal, language DEFAULT_IMAGE_ENABLED → channel.image_enabled DEFAULT_AI_STYLE_PROMPT → channel.ai_style_prompt DEFAULT_AUTO_DRAFT_COUNT/TIME → channel.auto_draft_count/time channels: image_enabled BOOLEAN DEFAULT true --- src/services/channels.js | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) 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 || []),