Compare commits
2 Commits
00198b8199
...
53b5924767
| Author | SHA1 | Date | |
|---|---|---|---|
| 53b5924767 | |||
| 8c445a7392 |
@ -23,6 +23,7 @@ export class SocketManager {
|
|||||||
// Create Socket.IO server - CORS applies to HTTP long-polling transport
|
// Create Socket.IO server - CORS applies to HTTP long-polling transport
|
||||||
const allowedOrigins = config.server.corsOrigins || ['*'];
|
const allowedOrigins = config.server.corsOrigins || ['*'];
|
||||||
const io = new Server(server, {
|
const io = new Server(server, {
|
||||||
|
maxHttpBufferSize: 1e8,
|
||||||
cors: {
|
cors: {
|
||||||
origin: (origin, callback) => {
|
origin: (origin, callback) => {
|
||||||
// Allow requests with no origin (e.g. same-origin, Postman, native apps)
|
// Allow requests with no origin (e.g. same-origin, Postman, native apps)
|
||||||
|
|||||||
@ -306,23 +306,41 @@ export class SocketUser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async handlePreviewTemplateEvent(data, callback) {
|
async handlePreviewTemplateEvent(data, callback) {
|
||||||
const result = await this.templateManager.renderTemplate(
|
try {
|
||||||
data._id,
|
const result = await this.templateManager.renderTemplate(
|
||||||
data.content,
|
data._id,
|
||||||
data.testObject,
|
data.content,
|
||||||
data.scale
|
data.testObject,
|
||||||
);
|
data.scale
|
||||||
callback(result);
|
);
|
||||||
|
if (typeof callback === 'function') {
|
||||||
|
callback(result);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
logger.error('Preview template event error:', err);
|
||||||
|
if (typeof callback === 'function') {
|
||||||
|
callback({ error: err.message });
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async handleRenderTemplatePDFEvent(data, callback) {
|
async handleRenderTemplatePDFEvent(data, callback) {
|
||||||
const result = await this.templateManager.renderPDF(
|
try {
|
||||||
data._id,
|
const result = await this.templateManager.renderPDF(
|
||||||
data.content,
|
data._id,
|
||||||
data.object,
|
data.content,
|
||||||
1
|
data.object,
|
||||||
);
|
1
|
||||||
callback(result);
|
);
|
||||||
|
if (typeof callback === 'function') {
|
||||||
|
callback(result);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
logger.error('Render template PDF event error:', err);
|
||||||
|
if (typeof callback === 'function') {
|
||||||
|
callback({ error: err.message });
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
async handleGenerateHostOtpEvent(data, callback) {
|
async handleGenerateHostOtpEvent(data, callback) {
|
||||||
const result = await generateHostOTP(data._id);
|
const result = await generateHostOTP(data._id);
|
||||||
|
|||||||
@ -407,6 +407,9 @@ export class TemplateManager {
|
|||||||
} else {
|
} else {
|
||||||
const objectType = documentTemplate?.objectType;
|
const objectType = documentTemplate?.objectType;
|
||||||
const model = getModelByName(objectType);
|
const model = getModelByName(objectType);
|
||||||
|
if (model == null) {
|
||||||
|
return { error: `Unknown object type: ${objectType}` };
|
||||||
|
}
|
||||||
const defaultKeys = Object.keys(model.schema.obj);
|
const defaultKeys = Object.keys(model.schema.obj);
|
||||||
const defaultValues = {};
|
const defaultValues = {};
|
||||||
for (const key of defaultKeys) {
|
for (const key of defaultKeys) {
|
||||||
@ -424,24 +427,37 @@ export class TemplateManager {
|
|||||||
|
|
||||||
var templateWithParentContent;
|
var templateWithParentContent;
|
||||||
|
|
||||||
|
var parentTemplate = documentTemplate.parent;
|
||||||
|
|
||||||
if (documentTemplate.parent != undefined) {
|
if (documentTemplate.parent != undefined) {
|
||||||
|
if (typeof parentTemplate === 'string') {
|
||||||
|
parentTemplate = await getObject({
|
||||||
|
model: documentTemplateModel,
|
||||||
|
id: parentTemplate,
|
||||||
|
populate: [
|
||||||
|
{ path: 'documentSize' },
|
||||||
|
{ path: 'parent', strictPopulate: false }
|
||||||
|
],
|
||||||
|
cached: true
|
||||||
|
});
|
||||||
|
}
|
||||||
// Validate parent content
|
// Validate parent content
|
||||||
if (
|
if (
|
||||||
documentTemplate.parent.content == null ||
|
parentTemplate.content == null ||
|
||||||
typeof documentTemplate.parent.content !== 'string'
|
typeof parentTemplate.content !== 'string'
|
||||||
) {
|
) {
|
||||||
logger.error(
|
logger.error(
|
||||||
'Parent template content is required and must be a string.',
|
'Parent template content is required and must be a string.',
|
||||||
documentTemplate.parent.content
|
parentTemplate.content
|
||||||
);
|
);
|
||||||
return {
|
return {
|
||||||
error:
|
error:
|
||||||
'Parent template content is required and must be a string.' +
|
'Parent template content is required and must be a string.' +
|
||||||
documentTemplate.parent.content
|
parentTemplate.content
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
templateWithParentContent = await ejs.render(
|
templateWithParentContent = await ejs.render(
|
||||||
documentTemplate.parent.content,
|
parentTemplate.content,
|
||||||
{ content: templateContent, fc: this.fc },
|
{ content: templateContent, fc: this.fc },
|
||||||
defaultOptions
|
defaultOptions
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user