feat(updater): Added exceptions logging (#2026)

* feat(updater): Added exceptions logging

* refactor(updater): Use `sha256` hash if available
This commit is contained in:
Roman Kelesidis 2025-07-02 10:16:54 +03:00 committed by GitHub
commit 57d0d59b53
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 120 additions and 60 deletions

View file

@ -18,9 +18,16 @@ if (!$bb_cfg['tp_updater_settings']['enabled']) {
}
$data = [];
$data[] = ['latest_check_timestamp' => TIMENOW];
$updaterDownloader = new \TorrentPier\Updater();
$updaterDownloader = $updaterDownloader->getLastVersion($bb_cfg['tp_updater_settings']['allow_pre_releases']);
try {
$updaterDownloader = new \TorrentPier\Updater();
$updaterDownloader = $updaterDownloader->getLastVersion($bb_cfg['tp_updater_settings']['allow_pre_releases']);
} catch (Exception $exception) {
bb_log('[Updater] Exception: ' . $exception->getMessage() . LOG_LF);
$this->store('check_updates', $data);
return;
}
$getVersion = \TorrentPier\Helpers\VersionHelper::removerPrefix($updaterDownloader['tag_name']);
$currentVersion = \TorrentPier\Helpers\VersionHelper::removerPrefix($bb_cfg['tp_version']);
@ -28,6 +35,7 @@ $currentVersion = \TorrentPier\Helpers\VersionHelper::removerPrefix($bb_cfg['tp_
// Has update!
if (\z4kn4fein\SemVer\Version::greaterThan($getVersion, $currentVersion)) {
$latestBuildFileLink = $updaterDownloader['assets'][0]['browser_download_url'];
$SHAFileHash = $updaterDownloader['assets'][0]['digest'] ?? '';
// Check updater file
$updaterFile = readUpdaterFile();
@ -41,10 +49,12 @@ if (\z4kn4fein\SemVer\Version::greaterThan($getVersion, $currentVersion)) {
]), UPDATER_FILE, replace_content: true);
}
// Get MD5 checksum
// Get MD5 / sha256 checksum
$buildFileChecksum = '';
if (isset($latestBuildFileLink)) {
$buildFileChecksum = strtoupper(md5_file($latestBuildFileLink));
if (!empty($SHAFileHash)) {
$buildFileChecksum = $SHAFileHash;
} else {
$buildFileChecksum = 'MD5: ' . strtoupper(md5_file($latestBuildFileLink));
}
// Build data array
@ -58,5 +68,4 @@ if (\z4kn4fein\SemVer\Version::greaterThan($getVersion, $currentVersion)) {
];
}
$data[] = ['latest_check_timestamp' => TIMENOW];
$this->store('check_updates', $data);

View file

@ -2229,10 +2229,10 @@ function infoByIP(string $ipAddress, int $port = 0): array
];
}
} else {
bb_log("[FreeIPAPI] Failed to get IP info for: $ipAddress");
bb_log("[FreeIPAPI] Failed to get IP info for: $ipAddress" . LOG_LF);
}
} catch (Exception $e) {
bb_log("[FreeIPAPI] " . $e->getMessage());
bb_log("[FreeIPAPI] " . $e->getMessage() . LOG_LF);
}
if (empty($data)) {