From a42e0d4d1a9ef9c217c0f28f15128a2249bb8490 Mon Sep 17 00:00:00 2001 From: Brock H Caldwell Date: Mon, 15 Sep 2025 12:33:16 -0500 Subject: [PATCH] fix: handles internal app version better --- config/services.yaml | 2 +- src/Base/ConfigResolver.php | 16 ++++++++++++++++ src/Base/Dto/AppVersionDto.php | 24 ++++++++++++++++++++++++ src/Twig/Extensions/UtilExtension.php | 10 ++++++++++ templates/bare.html.twig | 2 +- templates/components/NavBar.html.twig | 2 +- 6 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 src/Base/Dto/AppVersionDto.php diff --git a/config/services.yaml b/config/services.yaml index 4d9d2dc..b0cb080 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -32,7 +32,7 @@ parameters: app.cache.redis.host.default: 'redis://redis' # Various configs - app.default.version: '0.dev' + app.default.version: '0.0.0-dev' app.default.timezone: 'America/Chicago' # Auth diff --git a/src/Base/ConfigResolver.php b/src/Base/ConfigResolver.php index 5de8c61..3ea1f10 100644 --- a/src/Base/ConfigResolver.php +++ b/src/Base/ConfigResolver.php @@ -2,16 +2,25 @@ namespace App\Base; +use App\Base\Dto\AppVersionDto; use Symfony\Component\DependencyInjection\Attribute\Autowire; +use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; final class ConfigResolver { + const SEMVER_REGEX = '/^v?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/'; + private array $messages = []; public function __construct( + private readonly DenormalizerInterface $denormalizer, + #[Autowire(param: 'app.url')] private readonly ?string $appUrl = null, + #[Autowire(param: 'app.version')] + private readonly ?string $appVersion = null, + #[Autowire(param: 'app.debrid.real_debrid.key')] private readonly ?string $realDebridApiKey = null, @@ -92,6 +101,13 @@ final class ConfigResolver return $this->authOidcBypassFormLogin; } + public function getAppVersion(): AppVersionDto + { + $matches = []; + preg_match(self::SEMVER_REGEX, $this->appVersion, $matches); + return $this->denormalizer->denormalize($matches, AppVersionDto::class); + } + public function getAuthConfig(): array { return [ diff --git a/src/Base/Dto/AppVersionDto.php b/src/Base/Dto/AppVersionDto.php new file mode 100644 index 0000000..2b7fa05 --- /dev/null +++ b/src/Base/Dto/AppVersionDto.php @@ -0,0 +1,24 @@ +major . '.' . $this->minor . '.' . $this->patch . ($this->pre ? '-' . $this->pre : '') . ($this->build ? '+' . $this->build : ''); + } +} diff --git a/src/Twig/Extensions/UtilExtension.php b/src/Twig/Extensions/UtilExtension.php index 092012d..5e8799a 100644 --- a/src/Twig/Extensions/UtilExtension.php +++ b/src/Twig/Extensions/UtilExtension.php @@ -2,10 +2,13 @@ namespace App\Twig\Extensions; +use App\Base\ConfigResolver; +use App\Base\Dto\AppVersionDto; use App\Base\Service\MediaFiles; use App\Torrentio\Action\Result\GetTvShowOptionsResult; use App\Twig\Dto\EpisodeIdDto; use ChrisUllyott\FileSize; +use Symfony\Component\DependencyInjection\Attribute\Autowire; use Twig\Attribute\AsTwigFilter; use Twig\Attribute\AsTwigFunction; @@ -13,9 +16,16 @@ class UtilExtension { public function __construct( + private readonly ConfigResolver $config, private readonly MediaFiles $mediaFiles, ) {} + #[AsTwigFunction('app_version')] + public function app_version(): AppVersionDto + { + return $this->config->getAppVersion(); + } + #[AsTwigFunction('uniqid')] public function uniqid(): string { diff --git a/templates/bare.html.twig b/templates/bare.html.twig index b03b45b..1133f69 100644 --- a/templates/bare.html.twig +++ b/templates/bare.html.twig @@ -20,7 +20,7 @@ {% block body %}{% endblock %}
Sign In - v{{ version }} + {{ app_version() }}
diff --git a/templates/components/NavBar.html.twig b/templates/components/NavBar.html.twig index a0a3e9a..8c94eb0 100644 --- a/templates/components/NavBar.html.twig +++ b/templates/components/NavBar.html.twig @@ -55,7 +55,7 @@

- v{{ version|default('0.0') }} + {{ app_version() }}