Add MediaBlocklist feature
This commit is contained in:
parent
c2d194af1d
commit
ba1f7e7e2c
7 changed files with 206 additions and 44 deletions
|
@ -5,6 +5,7 @@ namespace App\Http\Controllers\Admin;
|
|||
use DB, Cache;
|
||||
use App\{
|
||||
Media,
|
||||
MediaBlocklist,
|
||||
Profile,
|
||||
Status
|
||||
};
|
||||
|
@ -21,8 +22,8 @@ trait AdminMediaController
|
|||
'nullable',
|
||||
'string',
|
||||
'min:1',
|
||||
'max:4',
|
||||
Rule::in(['grid','list'])
|
||||
'max:13',
|
||||
Rule::in(['grid','list', 'banned', 'addbanned'])
|
||||
],
|
||||
'search' => 'nullable|string|min:1|max:20'
|
||||
]);
|
||||
|
@ -34,9 +35,14 @@ trait AdminMediaController
|
|||
->whereIn('profile_id', $profiles)
|
||||
->orWhere('mime', $request->input('search'))
|
||||
->paginate(12);
|
||||
} else {
|
||||
$media = Media::whereHas('status')->with('status')->orderby('id', 'desc')->paginate(12);
|
||||
return view('admin.media.home', compact('media'));
|
||||
}
|
||||
|
||||
if($request->input('layout') == 'banned') {
|
||||
$media = MediaBlocklist::latest()->paginate(12);
|
||||
return view('admin.media.home', compact('media'));
|
||||
}
|
||||
$media = Media::whereHas('status')->with('status')->orderby('id', 'desc')->paginate(12);
|
||||
return view('admin.media.home', compact('media'));
|
||||
}
|
||||
|
||||
|
|
50
app/Http/Controllers/MediaBlocklistController.php
Normal file
50
app/Http/Controllers/MediaBlocklistController.php
Normal file
|
@ -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');
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue