InstanceService.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace App\Services;
  3. use Cache;
  4. use App\Instance;
  5. class InstanceService
  6. {
  7. public static function getByDomain($domain)
  8. {
  9. return Cache::remember('pf:services:instance:by_domain:'.$domain, 3600, function() use($domain) {
  10. return Instance::whereDomain($domain)->first();
  11. });
  12. }
  13. public static function getBannedDomains()
  14. {
  15. return Cache::remember('instances:banned:domains', now()->addHours(12), function() {
  16. return Instance::whereBanned(true)->pluck('domain')->toArray();
  17. });
  18. }
  19. public static function getUnlistedDomains()
  20. {
  21. return Cache::remember('instances:unlisted:domains', now()->addHours(12), function() {
  22. return Instance::whereUnlisted(true)->pluck('domain')->toArray();
  23. });
  24. }
  25. public static function getNsfwDomains()
  26. {
  27. return Cache::remember('instances:auto_cw:domains', now()->addHours(12), function() {
  28. return Instance::whereAutoCw(true)->pluck('domain')->toArray();
  29. });
  30. }
  31. public static function software($domain)
  32. {
  33. $key = 'instances:software:' . strtolower($domain);
  34. return Cache::remember($key, 86400, function() use($domain) {
  35. $instance = Instance::whereDomain($domain)->first();
  36. if(!$instance) {
  37. return;
  38. }
  39. return $instance->software;
  40. });
  41. }
  42. }