PixelfedVersions.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace App\Services;
  3. use Illuminate\Support\Facades\Cache;
  4. use Illuminate\Support\Str;
  5. use \Zttp\Zttp;
  6. class PixelfedVersions
  7. {
  8. public const VERSIONS = [
  9. '0.10.5',
  10. '0.10.6',
  11. '0.10.7',
  12. '0.10.8',
  13. '0.10.9'
  14. ];
  15. public static function get()
  16. {
  17. return Cache::rememberForever('px:join:software_versions', function() {
  18. try {
  19. $res = Zttp::timeout(30)
  20. ->get('https://api.github.com/repos/pixelfed/pixelfed/releases');
  21. } catch (\Zttp\ConnectionException $e) {
  22. return ksort(self::VERSIONS);
  23. } catch (\GuzzleHttp\Exception\RequestException $e) {
  24. return ksort(self::VERSIONS);
  25. }
  26. $json = collect($res->json());
  27. $res = $json->map(function($v) {
  28. return Str::startsWith($v['tag_name'], 'v') ? substr($v['tag_name'], 1) : $v['tag_name'];
  29. })->toArray();
  30. ksort($res);
  31. return $res;
  32. });
  33. }
  34. public static function latest()
  35. {
  36. $v = self::get()[0];
  37. return $v;
  38. }
  39. }