mirror of
https://github.com/Kizuren/statusPage.git
synced 2026-01-06 14:39:14 +01:00
Added negate parameter to be able to use Array content checks.
This commit is contained in:
parent
febe73226c
commit
e27966153a
1 changed files with 6 additions and 10 deletions
16
watcher.js
16
watcher.js
|
|
@ -5,19 +5,15 @@ const statusFile = './static/status.json';
|
||||||
|
|
||||||
const delay = async t=>new Promise(r=>setTimeout(r, t));
|
const delay = async t=>new Promise(r=>setTimeout(r, t));
|
||||||
const handlize = s=>s.toLowerCase().replace(/[^a-z0-9]/, ' ').trim().replace(/\s{2,}/g, '-');
|
const handlize = s=>s.toLowerCase().replace(/[^a-z0-9]/, ' ').trim().replace(/\s{2,}/g, '-');
|
||||||
const checkContent = async (content, criterion) => {
|
const checkContent = async (content, criterion, negate) => {
|
||||||
if(typeof criterion=='string') {
|
if(typeof criterion=='string') {
|
||||||
return content.includes(criterion);
|
return content.includes(criterion)!=negate;
|
||||||
} else if(Array.isArray(criterion)) {
|
} else if(Array.isArray(criterion)) {
|
||||||
return criterion.some(c=>content.includes(c));
|
return criterion[negate?'some':'every'](c=>content.includes(c))!=negate;
|
||||||
} else if(criterion instanceof RegExp) {
|
} else if(criterion instanceof RegExp) {
|
||||||
return !!content.match(criterion);
|
return (!!content.match(criterion))!=negate;
|
||||||
} else if(typeof criterion=='function') {
|
} else if(typeof criterion=='function') {
|
||||||
if(criterion.constructor.name == 'AsyncFunction') {
|
return (!!await Promise.resolve(criterion(content)))!=negate;
|
||||||
return !!criterion(content);
|
|
||||||
} else {
|
|
||||||
return !!await criterion(content);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Invalid content check criterion.')
|
throw new Error('Invalid content check criterion.')
|
||||||
}
|
}
|
||||||
|
|
@ -207,7 +203,7 @@ while(true) {
|
||||||
endpointStatus.err = '"mustFind" check failed';
|
endpointStatus.err = '"mustFind" check failed';
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(endpoint.mustNotFind && await checkContent(content, endpoint.mustNotFind)) {
|
if(endpoint.mustNotFind && !await checkContent(content, endpoint.mustNotFind, true)) {
|
||||||
endpointStatus.err = '"mustNotFind" check failed';
|
endpointStatus.err = '"mustNotFind" check failed';
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue