feat: content defaults — applied on channel creation

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
This commit is contained in:
Ник (Claude)
2026-06-13 11:22:08 +03:00
parent b5fa77ea01
commit 9b40f2cd7a
+32 -8
View File
@@ -47,18 +47,42 @@ async function createChannel(userId, data) {
if (!name) throw new Error('name is required'); 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( const { rows: chRows } = await query(
`INSERT INTO channels `INSERT INTO channels
(user_id, name, tg_channel_id, tg_username, bot_token, niche, audience, goal, language, region) (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) 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 *`, RETURNING *`,
[ [
userId, name, tg_channel_id || null, tg_username || null, bot_token || null, userId, name, tg_channel_id || null, tg_username || null, bot_token || null,
niche || null, audience || null, goal || 'educational', niche || null, audience || null,
language || 'ru', region || 'ru', goal || defGoal,
language || defLanguage,
region || 'ru',
defImageEnabled === 'true',
defStylePrompt || null,
parseInt(defDraftCount) || 3,
defDraftTime || '08:00',
] ]
); );
const channel = chRows[0]; const channel = chRows[0];
@@ -75,9 +99,9 @@ async function createChannel(userId, data) {
style.tone_custom || null, style.tone_custom || null,
style.formality || 'informal', style.formality || 'informal',
style.humor || 'moderate', style.humor || 'moderate',
style.post_length || 'medium', style.post_length || defLength,
style.structure || 'mixed', style.structure || 'mixed',
style.emoji_level || 'moderate', style.emoji_level || (defEmojiEnabled === 'true' ? 'moderate' : 'none'),
style.hashtags_mode || 'end', style.hashtags_mode || 'end',
style.cta_mode || 'sometimes', style.cta_mode || 'sometimes',
JSON.stringify(style.example_posts || []), JSON.stringify(style.example_posts || []),