Skip to content

Commit d277331

Browse files
author
Ajit Kumar
committed
feat: enhance supported_editor logic and add SQL logging in entity methods
1 parent 2acdfe0 commit d277331

2 files changed

Lines changed: 28 additions & 6 deletions

File tree

server/apis/plugin.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,12 @@ router.get('{/:pluginId}', async (req, res) => {
269269
where.push([Plugin.STATUS, status]);
270270
}
271271

272+
const origin = req.headers.origin || req.headers.referer;
273+
const allowAllEditors = Boolean(origin?.startsWith(process.env.HOST));
274+
272275
if (supported_editor && ['ace', 'cm', 'all'].includes(supported_editor)) {
273276
where.push([Plugin.SUPPORTED_EDITOR, supported_editor]);
274-
} else {
277+
} else if (!supported_editor && !allowAllEditors) {
275278
where.push([Plugin.SUPPORTED_EDITOR, 'all'], 'OR', [Plugin.SUPPORTED_EDITOR, 'ace']);
276279
}
277280
}

server/entities/entity.js

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ class Entity {
8181
operator,
8282
});
8383

84+
console.log('Generated SQL:', sql, 'Values:', values);
85+
8486
return Entity.execSql(sql, values, this);
8587
}
8688

@@ -281,21 +283,38 @@ class Entity {
281283
*/
282284
static formatWhere(where, operator = 'AND', values = []) {
283285
let result = '';
286+
let closeBracket = false;
284287
const [firstClause] = where;
288+
285289
if (!Array.isArray(firstClause)) {
286290
where = [where];
287291
}
292+
288293
where.forEach((condition, i) => {
289294
if (typeof condition === 'string') {
290295
return;
291296
}
292297

293-
const nextCondition = where[i + 1];
294-
result += ` ${formatCondition(condition)}`;
298+
const nextOperator = where[i + 1];
299+
300+
if (nextOperator && typeof nextOperator === 'string') {
301+
console.log('Next operator:', nextOperator);
302+
let clause = ` ${formatCondition(condition)} ${nextOperator} `;
303+
304+
if (!closeBracket && /OR/i.test(nextOperator)) {
305+
clause = ` ( ${clause}`;
306+
closeBracket = true;
307+
}
308+
309+
result += clause;
310+
} else {
311+
result += ` ${formatCondition(condition)} `;
312+
if (closeBracket) {
313+
result += ') ';
314+
closeBracket = false;
315+
}
295316

296-
if (nextCondition) {
297-
const thisOperator = typeof nextCondition === 'string' ? nextCondition : operator;
298-
result += ` ${thisOperator} `;
317+
result += ` ${operator} `;
299318
}
300319
});
301320

0 commit comments

Comments
 (0)