Created VersionHelper.php (#1731)

* Created `VersionHelper.php`

* Update VersionHelper.php

* Update CHANGELOG.md
This commit is contained in:
Roman Kelesidis 2025-01-02 12:34:13 +07:00 committed by GitHub
commit fd7dc7ac95
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 51 additions and 16 deletions

View file

@ -8,6 +8,7 @@
- Release 2.4.5 🍧️ ([belomaxorka](https://github.com/belomaxorka))
- Added `TorrentPier instance hash` generation [\#1726](https://github.com/torrentpier/torrentpier/pull/1726) ([belomaxorka](https://github.com/belomaxorka))
- Added `m4a` extension support in M3U playback [\#1724](https://github.com/torrentpier/torrentpier/pull/1724) ([belomaxorka](https://github.com/belomaxorka))
- Created `VersionHelper.php` [\#1731](https://github.com/torrentpier/torrentpier/pull/1731) ([belomaxorka](https://github.com/belomaxorka))
- Drop Ocelot announcer support 🫡 [\#1727](https://github.com/torrentpier/torrentpier/pull/1727) ([belomaxorka](https://github.com/belomaxorka))
- Show torrent's announcers list in `filelist.php` page [\#1708](https://github.com/torrentpier/torrentpier/pull/1708) ([belomaxorka](https://github.com/belomaxorka))
- [PHP 8.4] Fixed some deprecations [\#1718](https://github.com/torrentpier/torrentpier/pull/1718) ([belomaxorka](https://github.com/belomaxorka))

View file

@ -22,8 +22,8 @@ $data = [];
$updaterDownloader = new \TorrentPier\Updater();
$updaterDownloader = $updaterDownloader->getLastVersion($bb_cfg['tp_updater_settings']['allow_pre_releases']);
$getVersion = versionFormatter($updaterDownloader['tag_name']);
$currentVersion = versionFormatter($bb_cfg['tp_version']);
$getVersion = \TorrentPier\Helpers\VersionHelper::removerPrefix($updaterDownloader['tag_name']);
$currentVersion = \TorrentPier\Helpers\VersionHelper::removerPrefix($bb_cfg['tp_version']);
// Has update!
if (\z4kn4fein\SemVer\Version::greaterThan($getVersion, $currentVersion)) {

View file

@ -2157,20 +2157,6 @@ function readUpdaterFile(): array|bool
return json_decode(file_get_contents(UPDATER_FILE), true);
}
/**
* Version formatter
*
* @param string $version
* @return string
*/
function versionFormatter(string $version): string
{
$version = trim($version);
$version = mb_strtolower($version, 'UTF-8');
return str_replace('v', '', $version);
}
/**
* IP Geolocation API
*

View file

@ -0,0 +1,48 @@
<?php
/**
* TorrentPier Bull-powered BitTorrent tracker engine
*
* @copyright Copyright (c) 2005-2024 TorrentPier (https://torrentpier.com)
* @link https://github.com/torrentpier/torrentpier for the canonical source repository
* @license https://github.com/torrentpier/torrentpier/blob/master/LICENSE MIT License
*/
namespace TorrentPier\Helpers;
/**
* Class VersionHelper
* @package TorrentPier\Helpers
*/
class VersionHelper
{
/**
* Version prefix
*
* @var string
*/
private const VERSION_PREFIX = 'v';
/**
* Returns version without prefix (v)
*
* @param string $version
* @return string
*/
public static function removerPrefix(string $version): string
{
$version = trim($version);
$version = mb_strtolower($version, 'UTF-8');
return str_replace(self::VERSION_PREFIX, '', $version);
}
/**
* Returns version with prefix (v)
*
* @param string $version
* @return string
*/
public static function addPrefix(string $version): string
{
return self::VERSION_PREFIX . trim($version);
}
}