From 8c331da315b057752e4d469dc64e6d13cf0bfcf9 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sat, 13 Apr 2019 14:11:15 +0900 Subject: [PATCH] Fix bug --- src/server/api/endpoints/admin/logs.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/server/api/endpoints/admin/logs.ts b/src/server/api/endpoints/admin/logs.ts index e1419bdfe1..0ea3fbdbf7 100644 --- a/src/server/api/endpoints/admin/logs.ts +++ b/src/server/api/endpoints/admin/logs.ts @@ -34,7 +34,7 @@ export default define(meta, async (ps) => { if (ps.domain) { const whiteDomains = ps.domain.split(' ').filter(x => !x.startsWith('-')); - const blackDomains = ps.domain.split(' ').filter(x => x.startsWith('-')); + const blackDomains = ps.domain.split(' ').filter(x => x.startsWith('-')).map(x => x.substr(1)); if (whiteDomains.length > 0) { query.andWhere(new Brackets(qb => { @@ -53,11 +53,17 @@ export default define(meta, async (ps) => { if (blackDomains.length > 0) { query.andWhere(new Brackets(qb => { for (const blackDomain of blackDomains) { + const subDomains = blackDomain.split('.'); let i = 0; - for (const subDomain of blackDomain.split('.')) { + for (const subDomain of subDomains) { const p = `blackSubDomain_${subDomain}_${i}`; - // SQL is 1 based, so we need '+ 1' - qb.andWhere(`log.domain[${i + 1}] != :${p}`, { [p]: subDomain }); + if (i === subDomains.length - 1) { + // SQL is 1 based, so we need '+ 1' + qb.andWhere(`log.domain[${i + 1}] != :${p}`, { [p]: subDomain }); + } else { + // SQL is 1 based, so we need '+ 1' + qb.andWhere(`log.domain[${i + 1}] == :${p}`, { [p]: subDomain }); + } i++; } }