Save worktree changes

This commit is contained in:
2026-07-25 02:29:19 +01:00
parent 8d3b7d557b
commit db9d718cd8
170 changed files with 11719 additions and 3414 deletions
+54 -2
View File
@@ -2,6 +2,7 @@ const { fetchTemplateById } = require('./templates');
const { parseJsonSafe } = require('./utils');
const ALLOWED_RICH_TEXT_TAGS = ['b', 'strong', 'i', 'em', 'u', 'br', 'p', 'div', 'ul', 'ol', 'li'];
const DEFAULT_FONT_SIZE = 32;
function sanitizeRichText(html) {
let output = String(html || '');
@@ -60,10 +61,19 @@ function sanitizeTextColor(value, fallback) {
return fallback || '#000000';
}
function sanitizeFontSize(value, fallback) {
const raw = String(value || '').trim();
const parsed = Math.round(Number(raw.replace(/[^0-9.]/g, '')));
if (Number.isFinite(parsed) && parsed > 0) {
return parsed;
}
return Math.max(8, Number(fallback || DEFAULT_FONT_SIZE));
}
function getTextRegionStyle(body, region, existingContent) {
const existing = existingContent && existingContent[region.region_key] ? existingContent[region.region_key] : {};
const fontFamily = String(body[`region_font_family_${region.id}`] || existing.font_family || region.font_family || 'Arial').trim() || 'Arial';
const fontSize = Math.max(8, Number(body[`region_font_size_${region.id}`] || existing.font_size || 24));
const fontSize = sanitizeFontSize(body[`region_font_size_${region.id}`], existing.font_size || DEFAULT_FONT_SIZE);
const fontColor = sanitizeTextColor(body[`region_font_color_${region.id}`] || existing.font_color || region.font_color || '#000000');
return {
font_family: fontFamily,
@@ -80,7 +90,7 @@ function buildTemplateContent(template, body, filesByField, existingContent) {
const existing = body[`existing_region_image_${region.id}`];
content[region.region_key] = {
type: 'image',
value: uploaded ? `/uploads/${uploaded.filename}` : String(existing || '').trim() || ((existingContent && existingContent[region.region_key]) ? existingContent[region.region_key].value : '')
value: uploaded ? `/media/${uploaded.filename}` : String(existing || '').trim() || ((existingContent && existingContent[region.region_key]) ? existingContent[region.region_key].value : '')
};
} else if (region.region_type === 'webpage') {
const submitted = body[`region_webpage_${region.id}`];
@@ -89,6 +99,14 @@ function buildTemplateContent(template, body, filesByField, existingContent) {
type: 'webpage',
value: submitted === undefined ? current : String(submitted || '').trim()
};
} else if (region.region_type === 'rtmp') {
const submitted = body[`region_rtmp_${region.id}`];
const current = existingContent && existingContent[region.region_key] ? existingContent[region.region_key] : {};
content[region.region_key] = {
type: 'rtmp',
value: submitted === undefined ? String(current.value || '').trim() : String(submitted || '').trim(),
disable_audio: Boolean(body[`region_disable_audio_${region.id}`])
};
} else if (region.region_type === 'html') {
const submitted = body[`region_html_${region.id}`];
const current = existingContent && existingContent[region.region_key] ? existingContent[region.region_key].value : '';
@@ -96,6 +114,40 @@ function buildTemplateContent(template, body, filesByField, existingContent) {
type: 'html',
value: submitted === undefined ? current : String(submitted || '')
};
} else if (region.region_type === 'rss') {
const submitted = body[`region_text_${region.id}`];
const current = existingContent && existingContent[region.region_key] ? existingContent[region.region_key] : {};
const style = getTextRegionStyle(body, region, existingContent);
const feedId = body[`region_rss_feed_id_${region.id}`];
const itemNumber = body[`region_rss_item_number_${region.id}`];
const parsedItemNumber = Math.max(1, Number(itemNumber || current.item_number || 1));
content[region.region_key] = {
type: 'rss',
value: submitted === undefined ? String(current.value || '') : String(submitted || ''),
feed_id: feedId === undefined || feedId === null || feedId === '' ? (current.feed_id || null) : Number(feedId),
item_number: Number.isFinite(parsedItemNumber) && parsedItemNumber > 0 ? parsedItemNumber : 1,
variable_name: 'item',
font_family: style.font_family,
font_size: style.font_size,
font_color: style.font_color
};
} else if (region.region_type === 'api') {
const submitted = body[`region_text_${region.id}`];
const current = existingContent && existingContent[region.region_key] ? existingContent[region.region_key] : {};
const style = getTextRegionStyle(body, region, existingContent);
const sourceId = body[`region_api_source_id_${region.id}`];
const itemNumber = body[`region_api_item_number_${region.id}`];
const parsedItemNumber = Math.max(1, Number(itemNumber || current.item_number || 1));
content[region.region_key] = {
type: 'api',
value: submitted === undefined ? String(current.value || '') : String(submitted || ''),
source_id: sourceId === undefined || sourceId === null || sourceId === '' ? (current.source_id || null) : Number(sourceId),
item_number: Number.isFinite(parsedItemNumber) && parsedItemNumber > 0 ? parsedItemNumber : 1,
variable_name: 'item',
font_family: style.font_family,
font_size: style.font_size,
font_color: style.font_color
};
} else {
const submitted = body[`region_text_${region.id}`];
const current = existingContent && existingContent[region.region_key] ? existingContent[region.region_key].value : '';