Release v2.2.0

This commit is contained in:
2026-08-01 21:41:44 +01:00
parent c643d2fb07
commit d6417b667c
673 changed files with 146752 additions and 7389 deletions
+42 -9
View File
@@ -1,7 +1,6 @@
const { parseJsonSafe, readFormArray } = require('./utils');
// Template data access helpers and region normalization logic.
const ALLOWED_TEMPLATE_REGION_TYPES = ['text', 'image', 'video', 'webpage', 'html', 'rtmp', 'rss', 'api'];
const FONT_FAMILY_REGION_TYPES = ['text', 'html', 'rss', 'api'];
const { parseJsonSafe, readFormArray } = require('./utils');
function sanitizeBackgroundColor(value) {
const raw = String(value || '').trim();
@@ -13,7 +12,7 @@ function sanitizeBackgroundColor(value) {
function normalizeTemplateRegionType(value) {
const rawType = String(value || 'text').trim();
return ALLOWED_TEMPLATE_REGION_TYPES.includes(rawType) ? rawType : 'text';
return rawType || 'text';
}
function normalizeTemplateRegionLockRatio(value) {
@@ -58,7 +57,7 @@ async function fetchTemplateById(pool, id) {
return null;
}
const template = templates[0];
const [regions] = await pool.query('SELECT id, template_id, region_key, region_type, label, font_family, lock_ratio, x, y, width, height, z_index, created_at, modified_at, created_by, modified_by FROM c_template_regions WHERE template_id = ? ORDER BY z_index ASC, id ASC', [id]);
const [regions] = await pool.query('SELECT id, template_id, region_key, region_type, label, lock_ratio, x, y, width, height, z_index, created_at, modified_at, created_by, modified_by FROM c_template_regions WHERE template_id = ? ORDER BY z_index ASC, id ASC', [id]);
template.regions = regions;
return template;
}
@@ -71,7 +70,7 @@ async function fetchTemplatesData(pool) {
LEFT JOIN c_canvas_sizes cs ON cs.id = st.canvas_size_id
ORDER BY st.id DESC
`);
const [templateRegions] = await pool.query('SELECT id, template_id, region_key, region_type, label, font_family, lock_ratio, x, y, width, height, z_index, created_at, modified_at, created_by, modified_by FROM c_template_regions ORDER BY template_id ASC, z_index ASC, id ASC');
const [templateRegions] = await pool.query('SELECT id, template_id, region_key, region_type, label, lock_ratio, x, y, width, height, z_index, created_at, modified_at, created_by, modified_by FROM c_template_regions ORDER BY template_id ASC, z_index ASC, id ASC');
return { templates, templateRegions };
}
@@ -86,7 +85,6 @@ function extractTemplateRegions(body) {
region_key: String(region.region_name || region.region_key || region.label || '').trim(),
region_type: regionType,
label: String(region.region_name || region.label || region.region_key || '').trim(),
font_family: FONT_FAMILY_REGION_TYPES.includes(regionType) ? String(region.font_family || '').trim() || null : null,
lock_ratio: normalizeTemplateRegionLockRatio(region.lock_ratio),
x: Number(region.x || 0),
y: Number(region.y || 0),
@@ -108,7 +106,6 @@ function extractTemplateRegions(body) {
const widths = readFormArray(body, 'region_width[]');
const heights = readFormArray(body, 'region_height[]');
const zs = readFormArray(body, 'region_z[]');
const fonts = readFormArray(body, 'font_family[]');
const regions = [];
for (let i = 0; i < keys.length; i += 1) {
@@ -122,7 +119,6 @@ function extractTemplateRegions(body) {
region_key: name,
region_type: regionType,
label: name,
font_family: FONT_FAMILY_REGION_TYPES.includes(regionType) ? String(fonts[i] || 'Arial').trim() || 'Arial' : null,
lock_ratio: normalizeTemplateRegionLockRatio(ratios[i]),
x: Number(xs[i] || 0),
y: Number(ys[i] || 0),
@@ -135,6 +131,43 @@ function extractTemplateRegions(body) {
return regions;
}
function extractGenericRegionContent(region, body, filesByField, existingContent) {
const content = {};
const current = existingContent && existingContent[region.region_key] && typeof existingContent[region.region_key] === 'object' ? existingContent[region.region_key] : {};
const suffix = '_' + region.id;
Object.keys(body || {}).forEach((key) => {
if (!key.startsWith('region_') || !key.endsWith(suffix)) {
return;
}
const field = key.slice('region_'.length, -suffix.length);
if (!field || field === 'type' || field === 'key' || field === 'name' || field === 'label') {
return;
}
content[field] = body[key];
});
Object.keys(filesByField || {}).forEach((fieldName) => {
if (!fieldName.startsWith('region_') || !fieldName.endsWith(suffix)) {
return;
}
const field = fieldName.slice('region_'.length, -suffix.length);
if (!field) {
return;
}
content[field] = `/media/uploads/${filesByField[fieldName].filename}`;
});
Object.keys(current).forEach((key) => {
if (content[key] === undefined) {
content[key] = current[key];
}
});
content.type = region.region_type;
return content;
}
function getFilesByField(files) {
const map = {};
(files || []).forEach((file) => {