mirror of https://github.com/pixelfed/pixelfed
commit
351fe7035f
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\MediaBlocklist;
|
||||
|
||||
class MediaBlocklistController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
$this->middleware('admin');
|
||||
}
|
||||
|
||||
public function add(Request $request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'hash' => 'required|string|size:64',
|
||||
'name' => 'nullable|string',
|
||||
'description' => 'nullable|string|max:500',
|
||||
]);
|
||||
|
||||
$hash = $request->input('hash');
|
||||
abort_if(preg_match("/^([a-f0-9]{64})$/", $hash) !== 1, 400);
|
||||
|
||||
$name = $request->input('name');
|
||||
$description = $request->input('description');
|
||||
|
||||
$mb = new MediaBlocklist;
|
||||
$mb->sha256 = $hash;
|
||||
$mb->name = $name;
|
||||
$mb->description = $description;
|
||||
$mb->save();
|
||||
|
||||
return redirect('/i/admin/media?layout=banned');
|
||||
}
|
||||
|
||||
public function delete(Request $request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'id' => 'required|integer'
|
||||
]);
|
||||
|
||||
$media = MediaBlocklist::findOrFail($request->input('id'));
|
||||
$media->delete();
|
||||
|
||||
return redirect('/i/admin/media?layout=banned');
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class MediaBlocklist extends Model
|
||||
{
|
||||
//
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateMediaBlocklistsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('media_blocklists', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('sha256')->nullable()->unique()->index();
|
||||
$table->string('sha512')->nullable()->unique()->index();
|
||||
$table->string('name')->nullable();
|
||||
$table->text('description')->nullable();
|
||||
$table->boolean('active')->default(true)->index();
|
||||
$table->json('metadata')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('media_blocklists');
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue