MediaBlocklistService.php 719 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace App\Services;
  3. use Cache;
  4. use Illuminate\Support\Facades\File;
  5. use App\Media;
  6. use App\MediaBlocklist;
  7. class MediaBlocklistService
  8. {
  9. public static function get()
  10. {
  11. return MediaBlocklist::whereActive(true)
  12. ->pluck('sha256')
  13. ->toArray();
  14. }
  15. public static function exists($hash)
  16. {
  17. $hashes = self::get();
  18. return in_array($hash, $hashes) == true;
  19. }
  20. public static function remove($hash)
  21. {
  22. if(!self::exists($hash)) {
  23. return;
  24. }
  25. MediaBlocklist::whereSha256($hash)->delete();
  26. return;
  27. }
  28. public static function add($hash, $metadata)
  29. {
  30. $m = new MediaBlocklist;
  31. $m->sha256 = $hash;
  32. $m->active = true;
  33. $m->metadata = json_encode($metadata);
  34. $m->save();
  35. return $m;
  36. }
  37. }