FE: handling non-existent logs

Signed-off-by: jokob-sk <jokob.sk@gmail.com>
This commit is contained in:
jokob-sk
2025-11-05 16:13:28 +11:00
parent c08eb1dbba
commit 57096a9258
2 changed files with 17 additions and 16 deletions
+13 -14
View File
@@ -13,16 +13,22 @@ function renderLogArea($params) {
$textAreaCssClass = isset($params['textAreaCssClass']) ? $params['textAreaCssClass'] : ''; $textAreaCssClass = isset($params['textAreaCssClass']) ? $params['textAreaCssClass'] : '';
$buttons = isset($params['buttons']) ? $params['buttons'] : []; $buttons = isset($params['buttons']) ? $params['buttons'] : [];
$content = ""; $content = "";
$fileSize = 0;
if (filesize($filePath) > 2000000) { if (file_exists($filePath) && is_readable($filePath)) {
$content = file_get_contents($filePath, false, null, -2000000); $fileSize = filesize($filePath);
if ($fileSize > 2000000) {
$content = file_get_contents($filePath, false, null, max(0, $fileSize - 2000000));
} else {
$content = file_get_contents($filePath);
}
} else { } else {
$content = file_get_contents($filePath); $content = "⚠️ File not found or not readable: $filePath";
} }
// Prepare the download button HTML if filePath starts with /app // Prepare the download button HTML if filePath starts with /app
$downloadButtonHtml = ''; $downloadButtonHtml = '';
if (strpos($filePath, '/app') === 0) { if (strpos($filePath, '/app') === 0 && file_exists($filePath)) {
$downloadButtonHtml = ' $downloadButtonHtml = '
<span class="span-padding"> <span class="span-padding">
<a href="' . htmlspecialchars(str_replace('/app/log/', '/php/server/query_logs.php?file=', $filePath)) . '" target="_blank"> <a href="' . htmlspecialchars(str_replace('/app/log/', '/php/server/query_logs.php?file=', $filePath)) . '" target="_blank">
@@ -34,13 +40,7 @@ function renderLogArea($params) {
// Prepare buttons HTML // Prepare buttons HTML
$buttonsHtml = ''; $buttonsHtml = '';
$totalButtons = count($buttons); $totalButtons = count($buttons);
if ($totalButtons > 0) { $colClass = $totalButtons > 0 ? (12 / $totalButtons) : 12;
$colClass = 12 / $totalButtons;
// Use $colClass in your HTML generation or further logic
} else {
// Handle case where $buttons array is empty
$colClass = 12;
}
foreach ($buttons as $button) { foreach ($buttons as $button) {
$labelStringCode = isset($button['labelStringCode']) ? $button['labelStringCode'] : ''; $labelStringCode = isset($button['labelStringCode']) ? $button['labelStringCode'] : '';
@@ -52,8 +52,7 @@ function renderLogArea($params) {
</div>'; </div>';
} }
// Render HTML
// Render the log area HTML
$html = ' $html = '
<div class="log-area box box-solid box-primary"> <div class="log-area box box-solid box-primary">
<div class="row logs-row col-sm-12 col-xs-12"> <div class="row logs-row col-sm-12 col-xs-12">
@@ -63,7 +62,7 @@ function renderLogArea($params) {
</div> </div>
<div class="row logs-row"> <div class="row logs-row">
<div class="log-file col-sm-6 col-xs-12">' . htmlspecialchars($filePath) . ' <div class="log-file col-sm-6 col-xs-12">' . htmlspecialchars($filePath) . '
<div class="logs-size">' . number_format((filesize($filePath) / 1000000), 2, ",", ".") . ' MB' <div class="logs-size">' . number_format(($fileSize / 1000000), 2, ",", ".") . ' MB'
. $downloadButtonHtml . . $downloadButtonHtml .
'</div> '</div>
</div> </div>
+4 -2
View File
@@ -16,10 +16,12 @@ from const import applicationPath, logPath, apiPath, reportTemplatesPath
from logger import mylog, Logger from logger import mylog, Logger
from helper import generate_mac_links, \ from helper import generate_mac_links, \
removeDuplicateNewLines, \ removeDuplicateNewLines, \
timeNowDB, \
timeNowTZ, \
write_file, \ write_file, \
get_setting_value get_setting_value, \
get_timezone_offset
from messaging.in_app import write_notification from messaging.in_app import write_notification
from utils.datetime_utils import timeNowDB, get_timezone_offset
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------