diff --git a/src/Model/Release.php b/src/Model/Release.php index 80ee9c0afe663018063193321aca1d0b7a1f6fc4..e33ba92368b068ba8ff22a4d617946294a75f525 100644 --- a/src/Model/Release.php +++ b/src/Model/Release.php @@ -1,6 +1,7 @@ + * SPDX-FileCopyrightText: 2020 Carl Schwan * * SPDX-License-Identifier: AGPL-3.0-or-later */ @@ -15,20 +16,26 @@ class Release /** @var ReleaseType */ private $type; private $timestamp = null; + private $artifacts = []; + private $url; - public function __construct(string $version, int $type, string $timestamp) + public function __construct(string $version, int $type, string $timestamp, string $url = null, array $artifacts = []) { $this->version = $version; $this->type = $type; $this->timestamp = $timestamp; + $this->url = $url; + $this->artifacts = $artifacts; } public static function fromData(array $release): ?Release { + $url = isset($release['url']) && isset($release['url']['details']) ? $release['url']['details'] : null; + $artifacts = isset($release['artifacts']) ? $release['artifacts'] : []; if ($release['type'] === 'stable') { - return new Release($release['version'], ReleaseType::Stable, $release['unix-timestamp']); + return new Release($release['version'], ReleaseType::Stable, $release['unix-timestamp'],$url, $artifacts); } else if ($release['type'] === 'development') { - return new Release($release['version'], ReleaseType::Development, $release['unix-timestamp']); + return new Release($release['version'], ReleaseType::Development, $release['unix-timestamp'], $url, $artifacts); } else { return null; } @@ -58,4 +65,19 @@ class Release return $this->timestamp; } + /** + * @return array + */ + public function getArtifacts(): array + { + return $this->artifacts; + } + + /** + * @return string|null + */ + public function getUrl(): ?string + { + return $this->url; + } } diff --git a/src/Twig/AppTransExtension.php b/src/Twig/AppTransExtension.php index 98a9a50825711f2741c0ba75b65f3faa44e51219..716a9729ed3f8eff8f972c26e24d1539d9f90d0b 100644 --- a/src/Twig/AppTransExtension.php +++ b/src/Twig/AppTransExtension.php @@ -17,7 +17,8 @@ class AppTransExtension extends AbstractExtension public function getFilters() { return [ - new TwigFilter('l10n', [$this, 'l10n']) + new TwigFilter('l10n', [$this, 'l10n']), + new TwigFilter('size', [$this, 'size']), ]; } @@ -48,4 +49,23 @@ class AppTransExtension extends AbstractExtension } return $array['C']; } + + /** + * @param int $bytes + * @param int $precision + * @return string + * @throws Error + */ + public function size(int $bytes, int $precision = 2): string + { + $units = array('B', 'KB', 'MB', 'GB', 'TB'); + + $bytes = max($bytes, 0); + $pow = floor(($bytes ? log($bytes) : 0) / log(1024)); + $pow = min($pow, count($units) - 1); + + $bytes /= pow(1024, $pow); + + return round($bytes, $precision) . ' ' . $units[$pow]; + } } diff --git a/templates/main/application.html.twig b/templates/main/application.html.twig index 66756301809fac9fbc7e012621eef1d1d98736ce..45da81493ee809d466ab09cc1293525353a3265d 100644 --- a/templates/main/application.html.twig +++ b/templates/main/application.html.twig @@ -102,6 +102,52 @@ SPDX-License-Identifier: AGPL-3.0-or-later
{{ application.description | l10n(locale) | raw }}
+ {% if application.releases | length > 0 %} +

{% trans %}Releases{% endtrans %}

+ {% endif %} + {% for release in application.releases %} +
+

{{ release.version }} {{ release.timestamp | format_date('long', locale=locale) }}

+ + {% if release.url %} +
Learn more...
+ {% endif %} + {% if release.artifacts | length > 0 %} + {% for artifact in release.artifacts %} +
+ {% set size = "" %} + {% if artifact.size is defined and artifact.size.download %} + {% set size = " (" ~ artifact.size.download | size ~ ")" %} + {% endif %} + {% if artifact.type == "binary" %} +

+ {% if artifact.platform == "x86_64-appimage" or artifact.platform == "x86_64-linux-gnu" %} + {% trans %}AppImage{% endtrans %} - x86_64 {{ size }} + {% elseif artifact.platform == "macOS" %} + {% trans %}macOS{% endtrans %} - x86_64 {{ size }} + {% elseif artifact.platform == "win64" %} + {% trans %}Windows{% endtrans %} - win64 {{ size }} + {% elseif artifact.platform == "win32" %} + {% trans %}Windows{% endtrans %} - win32 {{ size }} + {% endif %} +

+
{{ artifact.locations[0] }}
+ {% for algo, checksum in artifact.checksum %} +
{{ algo }}: {{ checksum }}
+ {% endfor %} + {% else %} +

Source

+
{{ artifact.locations[0] }}
+ {% for algo, checksum in artifact.checksum %} + {{ algo }}: {{ checksum }} + {% endfor %} + {% endif %} +
+ {% endfor %} + {% endif %} +
+ {% endfor %} + Show more releases...