Release 2.16.0
This commit is contained in:
1 parent
821593dd8f
commit
3514d514a3
36 files changed
+2329
-346
No files matched your search
@@ -2,6 +2,7 @@
|
||||
|
||||
const { fetchTemplateById } = require('#src/data/templates');
|
||||
const { parseJsonSafe, validateMaxLength } = require('#src/data/utils');
|
||||
const { normalizeLayout } = require('#src/web/public/js/shared/region-layout');
|
||||
|
||||
const TITLE_MAX_LENGTH = 255;
|
||||
const { buildQrCodeContent } = require('#src/data/qr-code');
|
||||
@@ -622,6 +623,30 @@ async function buildSlidePayload(pool, req, existingSlide) {
|
||||
|
||||
if (template) {
|
||||
const content = await buildTemplateContent(pool, template, req.body, filesByField, existingContent);
|
||||
const submittedLayouts = req.body.region_layouts_json;
|
||||
let layouts = null;
|
||||
if (submittedLayouts !== undefined) {
|
||||
layouts = parseJsonSafe(submittedLayouts);
|
||||
if (!layouts || typeof layouts !== 'object' || Array.isArray(layouts)) {
|
||||
const error = new Error('Invalid slide layout.');
|
||||
error.statusCode = 400;
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
const canvas = { width: template.canvas_size_width, height: template.canvas_size_height };
|
||||
for (const region of template.regions) {
|
||||
const key = region.region_key;
|
||||
const value = layouts ? (Object.hasOwn(layouts, key) ? layouts[key] : null)
|
||||
: Number(existingSlide && existingSlide.template_id) === template.id && existingContent[key] && existingContent[key].layout;
|
||||
if (!value) continue;
|
||||
const layout = normalizeLayout(value, canvas);
|
||||
if (!layout) {
|
||||
const error = new Error('Invalid position or size for region ' + key + '.');
|
||||
error.statusCode = 400;
|
||||
throw error;
|
||||
}
|
||||
if (content[key]) content[key].layout = layout;
|
||||
}
|
||||
await Promise.all(Object.keys(content).map(async function (regionKey) {
|
||||
const region = template.regions.find(function (item) {
|
||||
return String(item.region_key || '').trim() === regionKey;
|
||||
@@ -630,7 +655,9 @@ async function buildSlidePayload(pool, req, existingSlide) {
|
||||
return;
|
||||
}
|
||||
|
||||
const layout = content[regionKey].layout;
|
||||
content[regionKey] = await buildQrCodeContent(content[regionKey]);
|
||||
if (layout) content[regionKey].layout = layout;
|
||||
}));
|
||||
|
||||
return {
|
||||
|
||||
Reference in new issue
Block a user