forked from mirror/pixelfed
Add MediaBlocklistService
This commit is contained in:
parent
8ffad2b615
commit
5d0a24a779
1 changed files with 44 additions and 0 deletions
44
app/Services/MediaBlocklistService.php
Normal file
44
app/Services/MediaBlocklistService.php
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services;
|
||||||
|
|
||||||
|
use Cache;
|
||||||
|
use Illuminate\Support\Facades\File;
|
||||||
|
use App\Media;
|
||||||
|
use App\MediaBlocklist;
|
||||||
|
|
||||||
|
class MediaBlocklistService
|
||||||
|
{
|
||||||
|
public static function get()
|
||||||
|
{
|
||||||
|
return MediaBlocklist::whereActive(true)
|
||||||
|
->pluck('sha256')
|
||||||
|
->toArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function exists($hash)
|
||||||
|
{
|
||||||
|
$hashes = self::get();
|
||||||
|
return in_array($hash, $hashes) == true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function remove($hash)
|
||||||
|
{
|
||||||
|
if(!self::exists($hash)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
MediaBlocklist::whereSha256($hash)->delete();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function add($hash, $metadata)
|
||||||
|
{
|
||||||
|
$m = new MediaBlocklist;
|
||||||
|
$m->sha256 = $hash;
|
||||||
|
$m->active = true;
|
||||||
|
$m->metadata = json_encode($metadata);
|
||||||
|
$m->save();
|
||||||
|
|
||||||
|
return $m;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue