1
0
Fork 1
mirror of https://github.com/pixelfed/pixelfed.git synced 2024-12-30 11:44:59 +00:00
pixelfed/app/Http/Controllers/Api/AdminApiController.php

118 lines
3 KiB
PHP
Raw Normal View History

2019-08-20 01:07:25 +00:00
<?php
namespace App\Http\Controllers\Api;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Jobs\StatusPipeline\StatusDelete;
use Auth, Cache;
use Carbon\Carbon;
use App\{
Like,
Media,
Profile,
Status
};
use App\Services\NotificationService;
class AdminApiController extends Controller
{
public function __construct()
{
$this->middleware(['auth', 'admin']);
}
public function activity(Request $request)
{
$activity = [];
$limit = request()->input('limit', 20);
$activity['captions'] = Status::select(
'id',
'caption',
'rendered',
'uri',
'profile_id',
'type',
'in_reply_to_id',
'reblog_of_id',
'is_nsfw',
'scope',
'created_at'
)->whereNull('in_reply_to_id')
->whereNull('reblog_of_id')
->orderByDesc('created_at')
->paginate($limit);
$activity['comments'] = Status::select(
'id',
'caption',
'rendered',
'uri',
'profile_id',
'type',
'in_reply_to_id',
'reblog_of_id',
'is_nsfw',
'scope',
'created_at'
)->whereNotNull('in_reply_to_id')
->whereNull('reblog_of_id')
->orderByDesc('created_at')
->paginate($limit);
return response()->json($activity, 200, [], JSON_PRETTY_PRINT);
}
public function moderateStatus(Request $request)
{
2019-08-23 04:33:04 +00:00
abort(400, 'Unpublished API');
return;
2019-08-20 01:07:25 +00:00
$this->validate($request, [
'type' => 'required|string|in:status,profile',
'id' => 'required|integer|min:1',
'action' => 'required|string|in:cw,unlink,unlist,suspend,delete'
]);
$type = $request->input('type');
$id = $request->input('id');
$action = $request->input('action');
if ($type == 'status') {
$status = Status::findOrFail($id);
switch ($action) {
case 'cw':
$status->is_nsfw = true;
$status->save();
break;
case 'unlink':
$status->rendered = $status->caption;
$status->save();
break;
case 'unlist':
$status->scope = 'unlisted';
$status->visibility = 'unlisted';
$status->save();
break;
default:
break;
}
} else if ($type == 'profile') {
$profile = Profile::findOrFail($id);
switch ($action) {
case 'delete':
StatusDelete::dispatch($status);
break;
default:
break;
}
}
}
}