Skip to content

Commit 72fd30a

Browse files
authored
54 configure a way to excludeinclude incoming data based on criteria (#95)
* Adding messageCriteria module and new environment variables * Adding profanity-list.json with curse words * Adding containsCurseWord function * Updating .env file * Adding logical gate to check if messages should go through or not * Adding logic to messageCriteria * Adding unit tests for messageCriteria * Updating environment variables * Updating Ansible scripts with environment variables
1 parent 63dfc3f commit 72fd30a

13 files changed

+3119
-10
lines changed

.env

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
1-
# Database ENV variables
1+
# database variables
22
DATABASE_URL=
33
DEV_DATABASE_URL=postgres://postgres:[email protected]:5432/hugin_cache_dev
44
TEST_DATABASE_URL=postgres://postgres:[email protected]:5432/hugin_cache_test
55

6-
# Other
6+
# other
77
NODE_ENV=development
88
API_BASE_PATH=/api/v1
99

10-
SYS_HUGIN_NODE_SERVER=blocksum.org:11898
10+
SYS_HUGIN_NODE_SERVER=blocksum.org:11898
11+
12+
# criteria configuration
13+
SYS_CRITERIA_USERS_INCLUDE="" # set to only include specific users - cannot be used with both exclude
14+
SYS_CRITERIA_USERS_EXCLUDE="" # set to include all users except - cannot be used both with include
15+
16+
SYS_CRITERIA_BOARDS_INCLUDE="" # set to only include specific boards - cannot be used with both exclude
17+
SYS_CRITERIA_BOARDS_EXCLUDE="" # set to include all boards except - cannot be used both with include
18+
19+
SYS_CRITERIA_KEYWORDS_INCLUDE="" # set to only include specific keywords - cannot be used with both exclude
20+
SYS_CRITERIA_KEYWORDS_EXCLUDE="" # set to include all keywords except - cannot be used both with include
21+
SYS_CRITERIA_KEYWORDS_CURSEWORDS=true # controls if curse words should be excluded

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ And a lot of other packages/libraries which can seen in **package.json**.
4848

4949
# Websockets
5050

51-
We have implemented Websockets that are listening on `wss://<domain>`.
51+
We have implemented Websockets that are listening on `wss://<domain>`. You can try it out using [Websocket King Client](https://websocketking.com/).
52+
53+
![Websockets](websockets.png)
5254

5355
# API Endpoints
5456

ansible/provision_vps.yml

+8
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@
2828
index_file_url: 'https://{{ domain_name }}/api/v1/posts'
2929
index_file_path: 'https://raw.githubusercontent.com/TechyGuy17/Hugin-cache-homepage/master/index.html.j2'
3030

31+
sys_criteria_users_include: ''
32+
sys_criteria_users_exclude: ''
33+
sys_criteria_boards_include: ''
34+
sys_criteria_boards_exclude: ''
35+
sys_criteria_keywords_include: ''
36+
sys_criteria_keywords_exclude: ''
37+
sys_criteria_keywords_cursewords: 'false'
38+
3139
roles:
3240
#- base
3341
- postgres

ansible/roles/docker/tasks/main.yml

+8-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,14 @@
9898
command: "./start.sh"
9999
env: {
100100
DATABASE_URL: "postgres://{{ vault_postgres_db_user }}:{{ vault_postgres_db_password }}@127.0.0.1:5432/{{ vault_postgres_db_name }}",
101-
SYS_HUGIN_NODE_SERVER: "{{ hugin_node_server }}"
101+
SYS_HUGIN_NODE_SERVER: "{{ hugin_node_server }}",
102+
SYS_CRITERIA_USERS_INCLUDE: "",
103+
SYS_CRITERIA_USERS_EXCLUDE: "",
104+
SYS_CRITERIA_BOARDS_INCLUDE: "",
105+
SYS_CRITERIA_BOARDS_EXCLUDE: "",
106+
SYS_CRITERIA_KEYWORDS_INCLUDE: "",
107+
SYS_CRITERIA_KEYWORDS_EXCLUDE: "",
108+
SYS_CRITERIA_KEYWORDS_CURSEWORDS: "false"
102109
}
103110
networks:
104111
- name: "host"

ansible/roles/nginx/templates/nginx-le.j2

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ server {
3232
root /var/www/html/;
3333
index index.html;
3434

35-
location / {
35+
location /ws {
3636
proxy_pass http://{{ hugin_cache_name }}_ws;
3737
proxy_http_version 1.1;
3838
proxy_set_header Upgrade $http_upgrade;

configs/huginSyncer.js

+13-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const { extraDataToMessage } = require('hugin-crypto')
1111
const { performance } = require('perf_hooks')
1212

1313
const { getTimestamp } = require('../utils/time')
14+
const { messageCriteria } = require('../utils/messageCriteria')
1415

1516
let db = require("./postgresql"),
1617
sequelize = db.sequelize,
@@ -47,7 +48,6 @@ module.exports.backgroundSyncMessages = async () => {
4748
let transactions = json.addedTxs;
4849
let transaction;
4950

50-
// known_pooL_txs = known_pooL_txs.filter(n => !json.deletedTxsIds.includes(n)) // fixing https://github.com/kryptokrona/hugin-cache/issues/86
5151
if (transactions.length === 0) {
5252
log.info(getTimestamp() + ' INFO: Got empty transaction array.')
5353
return;
@@ -73,7 +73,6 @@ module.exports.backgroundSyncMessages = async () => {
7373
privateViewKey: '0000000000000000000000000000000000000000000000000000000000000000'
7474
}
7575

76-
7776
// if extra is less than 200 length - skip
7877
let message
7978
if (thisExtra !== undefined && thisExtra.length > 200) {
@@ -89,7 +88,7 @@ module.exports.backgroundSyncMessages = async () => {
8988

9089
if ((message || message !== undefined) && (message.brd || message.brd !== undefined)) {
9190
log.info(getTimestamp() + ' INFO: Got 1 message. Message: ' + JSON.stringify(message))
92-
91+
9392
let messageObj = {
9493
message: message.m || null,
9594
key: message.k || null,
@@ -101,6 +100,17 @@ module.exports.backgroundSyncMessages = async () => {
101100
reply: message.r ||null
102101
}
103102

103+
// skipping based on criteria - if criteria exists
104+
const criteriaFulfilled = messageCriteria(messageObj)
105+
106+
// criteria guard
107+
if (!criteriaFulfilled) {
108+
log.info(getTimestamp() + ' INFO: Message does not meet criteria based on configuration: ' + JSON.stringify(message))
109+
continue
110+
}
111+
112+
log.info(getTimestamp() + ' INFO: Criteria fulfilled.')
113+
104114
// broadcast message object to websocket server
105115
ws.send(JSON.stringify(messageObj))
106116

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"db:migrate": "npx sequelize-cli db:migrate",
1212
"db:reset": "npx sequelize-cli db:drop && npx sequelize-cli db:create && npx sequelize-cli db:migrate && npx sequelize-cli db:seed:all --seeders-path ./database/seeders",
1313
"db:create:test": "cross-env NODE_ENV=test npx sequelize-cli db:create",
14-
"code-coverage": "npx c8 --check-coverage --lines 75 npm test",
14+
"code-coverage": "npx c8 --check-coverage --lines 70 npm test",
1515
"code-coverage-report": "npx c8 report --temp-directory .c8 -o ./.c8/html_coverage -r html && open ./.c8/html_coverage/index.html"
1616
},
1717
"repository": {

0 commit comments

Comments
 (0)