2024-12-02 17:06:49 +01:00
exports . id = 'nodesdb_change_check' ;
exports . title = 'Nodes DB change check' ;
exports . group = 'Worksys' ;
exports . color = '#888600' ;
exports . version = '1.0.2' ;
exports . icon = 'sign-out' ;
exports . input = 1 ;
exports . output = 1 ;
exports . readme = ` Check, if nodes.table db changed compared to original database ` ;
const fs = require ( 'fs' ) ;
const path = require ( 'path' ) ;
const { sendNotification } = require ( './helper/notification_reporter' ) ;
const nodesOriginalFile = path . join ( _ _dirname , '../databases/nodes_original/' , 'nodes_original.table' ) ;
exports . install = function ( instance ) {
2025-10-19 19:47:04 +02:00
function compareArrays ( array1 , array2 ) {
let message = "" ;
let areEqual = true ;
let zmenene = [ ]
2024-12-02 17:06:49 +01:00
2025-10-19 19:47:04 +02:00
if ( array1 . length !== array2 . length ) {
message += "Nezhoda v pocte nodov. "
}
2024-12-02 17:06:49 +01:00
2025-10-19 19:47:04 +02:00
const set1 = new Set ( array1 . map ( obj => JSON . stringify ( obj ) ) ) ;
const set2 = new Set ( array2 . map ( obj => JSON . stringify ( obj ) ) ) ;
2024-12-02 17:06:49 +01:00
2025-10-19 19:47:04 +02:00
for ( const objStr of set1 ) {
2024-12-02 17:06:49 +01:00
2025-10-19 19:47:04 +02:00
if ( ! set2 . has ( objStr ) ) {
zmenene . push ( objStr )
areEqual = false ;
} else {
set2 . delete ( objStr ) ;
2024-12-02 17:06:49 +01:00
}
2025-10-19 19:47:04 +02:00
}
2024-12-02 17:06:49 +01:00
2025-10-19 19:47:04 +02:00
if ( ! areEqual ) {
message += ` Aktualne nody: ${ zmenene . toString ( ) } . Zmenene proti originalu: ${ Array . from ( set2 ) . join ( ' ' ) } ` ;
sendNotification ( "Nodesdb_changecheck" , FLOW . GLOBALS . settings . rvoTbName , "nodes_db_changed" , "" , message , 0 , instance ) ;
2024-12-02 17:06:49 +01:00
}
2025-10-19 19:47:04 +02:00
else console . log ( "Arrays are equal." ) ;
2024-12-02 17:06:49 +01:00
2025-10-19 19:47:04 +02:00
console . log ( message )
}
2024-12-02 17:06:49 +01:00
2025-10-19 19:47:04 +02:00
instance . on ( "data" , _ => {
2024-12-02 17:06:49 +01:00
2025-10-19 19:47:04 +02:00
let nodesData = FLOW . GLOBALS . nodesData ;
2024-12-02 17:06:49 +01:00
2025-10-19 19:47:04 +02:00
// we check if nodes.table has changed compared to nodes_original.table (we have array of nodes e.g. [{node:255, tbname: "agruhuwhgursuhgo34hgsdiguhrr"}]
const nodes _actual = Object . keys ( nodesData ) . map ( node => ( { [ node ] : nodesData [ node ] . tbname } ) )
let nodes _original = fs . readFileSync ( nodesOriginalFile , { encoding : 'utf8' , flag : 'r' } ) ;
try {
nodes _original = JSON . parse ( nodes _original ) ;
} catch ( e ) {
console . log ( e )
}
2024-12-02 17:06:49 +01:00
2025-10-19 19:47:04 +02:00
setTimeout ( ( ) => compareArrays ( nodes _actual , nodes _original ) , 10000 ) ;
} )
2024-12-02 17:06:49 +01:00
}