From 3c77ae7b62aecb98dcd77808c41fee189afacdec Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 3 Mar 2019 08:13:49 +0900 Subject: [PATCH] Improve log api --- src/server/api/endpoints/admin/logs.ts | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/server/api/endpoints/admin/logs.ts b/src/server/api/endpoints/admin/logs.ts index 3331b92314..805a42b9e0 100644 --- a/src/server/api/endpoints/admin/logs.ts +++ b/src/server/api/endpoints/admin/logs.ts @@ -34,10 +34,26 @@ export default define(meta, async (ps) => { if (ps.level) query.level = ps.level; if (ps.domain) { - let i = 0; - for (const d of ps.domain.split('.')) { - query[`domain.${i}`] = d; - i++; + for (const d of ps.domain.split(' ')) { + const qs: any[] = []; + let i = 0; + for (const sd of (d.startsWith('-') ? d.substr(1) : d).split('.')) { + qs.push({ + [`domain.${i}`]: d.startsWith('-') ? { $ne: sd } : sd + }); + i++; + } + if (d.startsWith('-')) { + if (query['$and'] == null) query['$and'] = []; + query['$and'].push({ + $and: qs + }); + } else { + if (query['$or'] == null) query['$or'] = []; + query['$or'].push({ + $and: qs + }); + } } }