From 0d83ed31796f55b70c5f7b988055d4ff75a86f54 Mon Sep 17 00:00:00 2001 From: jokob-sk Date: Sat, 8 Jun 2024 09:34:07 +1000 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=83=20Sync=20Hub=20v0.7.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- front/plugins/sync/hub.php | 3 ++- front/plugins/sync/sync.py | 20 ++++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/front/plugins/sync/hub.php b/front/plugins/sync/hub.php index 48c15c50..941f6ec7 100755 --- a/front/plugins/sync/hub.php +++ b/front/plugins/sync/hub.php @@ -35,10 +35,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { } // Generate a unique file path to avoid overwriting existing files - $files = glob("{$storage_path}/last_result.encoded.{$node_name}.*.log"); + $files = glob("{$storage_path}/last_result.{encoded,decoded}.{$node_name}.*.log", GLOB_BRACE); $file_count = count($files) + 1; $file_path = "{$storage_path}/last_result.encoded.{$node_name}.{$file_count}.log"; + // Save the decoded data to the file file_put_contents($file_path, $data); http_response_code(200); diff --git a/front/plugins/sync/sync.py b/front/plugins/sync/sync.py index 7763be3f..0049680e 100755 --- a/front/plugins/sync/sync.py +++ b/front/plugins/sync/sync.py @@ -106,23 +106,27 @@ def main(): mylog('verbose', [f'[{pluginName}] Devices files to process: "{files_to_process}"']) - for file_path in files_to_process: + for file_name in files_to_process: # only process received .log files, skipping the one logging the progress of this plugin - if file_path != 'last_result.log': - mylog('verbose', [f'[{pluginName}] Processing: "{file_path}"']) + if file_name != 'last_result.log': + mylog('verbose', [f'[{pluginName}] Processing: "{file_name}"']) # Store e.g. Node_1 from last_result.encoded.Node_1.1.log tmp_SyncHubNodeName = '' - if len(file_path.split('.')) > 3: - tmp_SyncHubNodeName = file_path.split('.')[2] + if len(file_name.split('.')) > 3: + tmp_SyncHubNodeName = file_name.split('.')[2] + + + file_path = f"{INSTALL_PATH}/front/plugins/sync/{file_name}" with open(file_path, 'r') as f: data = json.load(f) for device in data['data']: - device['dev_SyncHubNodeName'] = tmp_SyncHubNodeName - unique_mac_addresses.add(device['dev_MAC']) - device_data.append(device) + if device['dev_MAC'] not in unique_mac_addresses: + device['dev_SyncHubNodeName'] = tmp_SyncHubNodeName + unique_mac_addresses.add(device['dev_MAC']) + device_data.append(device) if len(device_data) > 0: # Retrieve existing dev_MAC values from the Devices table