badmfck-api-server 4.0.64 → 4.0.66
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -451,13 +451,13 @@ class MysqlAdapter {
|
|
|
451
451
|
let total = null;
|
|
452
452
|
;
|
|
453
453
|
if (request.calculateCount) {
|
|
454
|
-
const cres = await conn.query(
|
|
454
|
+
const cres = await conn.query(this.prepareCountQuery(query));
|
|
455
455
|
if (cres && cres[0]) {
|
|
456
456
|
const res = cres[0];
|
|
457
|
-
if (Array.isArray(res) && res.length > 0 && "
|
|
458
|
-
total = res[0].
|
|
459
|
-
else if ("
|
|
460
|
-
total = res.
|
|
457
|
+
if (Array.isArray(res) && res.length > 0 && "count" in res[0])
|
|
458
|
+
total = res[0].count;
|
|
459
|
+
else if ("count" in res)
|
|
460
|
+
total = res.count;
|
|
461
461
|
}
|
|
462
462
|
}
|
|
463
463
|
this.lastSuccessQueryTime = +new Date();
|
|
@@ -644,14 +644,11 @@ class MysqlAdapter {
|
|
|
644
644
|
return value;
|
|
645
645
|
}
|
|
646
646
|
prepareCountQuery(query) {
|
|
647
|
-
let
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
countQuery = countQuery.substring(countQuery.indexOf("FROM"));
|
|
653
|
-
countQuery = "SELECT COUNT(1) as `count` " + countQuery;
|
|
654
|
-
return countQuery;
|
|
647
|
+
let cleanQuery = query
|
|
648
|
+
.replace(/ORDER\s+BY\s+.*$/is, "")
|
|
649
|
+
.replace(/\bLIMIT\s+\d+(\s+OFFSET\s+\d+)?/is, "")
|
|
650
|
+
.trim();
|
|
651
|
+
return `SELECT COUNT(1) AS \`count\` FROM (${cleanQuery}) AS \`temp_count_table\``;
|
|
655
652
|
}
|
|
656
653
|
async commit(trx) {
|
|
657
654
|
try {
|
|
@@ -55,9 +55,10 @@ class MicroserviceClient extends BaseService_1.BaseService {
|
|
|
55
55
|
const resp = await Http_1.Http.post(url, { tag: tag.toString("base64"), enc: encrypted.toString("base64") }, { headers });
|
|
56
56
|
if (!resp.ok)
|
|
57
57
|
return { ...DefaultErrors_1.default.BAD_REQUEST, details: resp.details, stack: [resp.error] };
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
const body = resp.data;
|
|
59
|
+
if (body && typeof body === "object" && "error" in body)
|
|
60
|
+
return body.error;
|
|
61
|
+
return body.data ?? null;
|
|
61
62
|
}
|
|
62
63
|
}
|
|
63
64
|
exports.MicroserviceClient = MicroserviceClient;
|
|
@@ -132,7 +132,7 @@ class Monitor extends BaseEndpoint_1.BaseEndpoint {
|
|
|
132
132
|
async checkAuthentication(req) {
|
|
133
133
|
const users = await APIService_1.REQ_MONITOR_USERS.request();
|
|
134
134
|
if (!users || users.length == 0)
|
|
135
|
-
throw { ...DefaultErrors_1.default.UNAUTHORIZED, details: "No users found for
|
|
135
|
+
throw { ...DefaultErrors_1.default.UNAUTHORIZED, details: "No users found for monitor access, please set up users first." };
|
|
136
136
|
let header = req.headers['authorization'];
|
|
137
137
|
if (!header)
|
|
138
138
|
throw { ...DefaultErrors_1.default.UNAUTHORIZED, details: "No authorization header found" };
|