-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[OGUI-1455] Logging live mode filters/criteria #2684
base: dev
Are you sure you want to change the base?
Changes from 3 commits
e2001a2
0fcbd85
67ddc35
aa260c5
7d5a297
47cb0fd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -133,6 +133,42 @@ | |
client.on('error', (err) => this.logger.error(`Connection ${err.code}`)); | ||
} | ||
|
||
/** | ||
* Make criteria more readable. | ||
* This code is a close copy of InfoLogger/public/logFilter/LogFilter.js LN 101 toObject() | ||
* @param {object} criteria - criteria to be minified | ||
* @returns {object} minimal filter object | ||
*/ | ||
minifyCriteria(criteria) { | ||
// Copy everything | ||
const criterias = JSON.parse(JSON.stringify(criteria)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently this function |
||
|
||
// Clean-up the whole structure | ||
|
||
for (const field in criterias) { | ||
for (const operator in criterias[field]) { | ||
// Remote parsed properties (generated with fromJSON) | ||
if (operator.includes('$')) { | ||
delete criterias[field][operator]; | ||
} | ||
|
||
// Remote empty inputs | ||
if (!criterias[field][operator]) { | ||
delete criterias[field][operator]; | ||
} else if (operator === 'match' || operator === 'exclude') { | ||
// Encode potential breaking characters and escape double quotes as are used by browser by default | ||
criterias[field][operator] = encodeURI(criterias[field][operator].replace(/["]+/g, '\\"')); | ||
} | ||
|
||
// Remove empty fields | ||
if (!Object.keys(criterias[field]).length) { | ||
delete criterias[field]; | ||
} | ||
} | ||
} | ||
return criterias; | ||
} | ||
|
||
/** | ||
* Called when a new message arrives | ||
* Handles connection with a client | ||
|
@@ -146,6 +182,10 @@ | |
// 2. Check if its message filter (no auth required) | ||
if (parsed.getCommand() == 'filter' && parsed.getPayload()) { | ||
client.filter = new Function(`return ${parsed.getPayload()}`)(); | ||
const criterias = this.minifyCriteria(client.filter(message, true)); | ||
if (criterias != false) { | ||
this.logger.debugMessage(`New live filter applied: ${JSON.stringify(criterias)}`); | ||
} | ||
} | ||
// 3. Get reply if callback exists | ||
this.processRequest(parsed) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Houwie7000 as this is a utility function, I think it is better if we move it to an independent JS module in an utility folder.
As currently there is no such folder, please create one and add this function to its own module. Then call it from there in the WS server.
The tests associated to this function should match the folder structure as well