AdminApiController.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\Controller;
  5. use App\Jobs\StatusPipeline\StatusDelete;
  6. use Auth, Cache;
  7. use Carbon\Carbon;
  8. use App\{
  9. Like,
  10. Media,
  11. Profile,
  12. Status
  13. };
  14. use App\Services\NotificationService;
  15. class AdminApiController extends Controller
  16. {
  17. public function __construct()
  18. {
  19. $this->middleware(['auth', 'admin']);
  20. }
  21. public function activity(Request $request)
  22. {
  23. $activity = [];
  24. $limit = request()->input('limit', 20);
  25. $activity['captions'] = Status::select(
  26. 'id',
  27. 'caption',
  28. 'rendered',
  29. 'uri',
  30. 'profile_id',
  31. 'type',
  32. 'in_reply_to_id',
  33. 'reblog_of_id',
  34. 'is_nsfw',
  35. 'scope',
  36. 'created_at'
  37. )->whereNull('in_reply_to_id')
  38. ->whereNull('reblog_of_id')
  39. ->orderByDesc('created_at')
  40. ->paginate($limit);
  41. $activity['comments'] = Status::select(
  42. 'id',
  43. 'caption',
  44. 'rendered',
  45. 'uri',
  46. 'profile_id',
  47. 'type',
  48. 'in_reply_to_id',
  49. 'reblog_of_id',
  50. 'is_nsfw',
  51. 'scope',
  52. 'created_at'
  53. )->whereNotNull('in_reply_to_id')
  54. ->whereNull('reblog_of_id')
  55. ->orderByDesc('created_at')
  56. ->paginate($limit);
  57. return response()->json($activity, 200, [], JSON_PRETTY_PRINT);
  58. }
  59. public function moderateStatus(Request $request)
  60. {
  61. $this->validate($request, [
  62. 'type' => 'required|string|in:status,profile',
  63. 'id' => 'required|integer|min:1',
  64. 'action' => 'required|string|in:cw,unlink,unlist,suspend,delete'
  65. ]);
  66. $type = $request->input('type');
  67. $id = $request->input('id');
  68. $action = $request->input('action');
  69. if ($type == 'status') {
  70. $status = Status::findOrFail($id);
  71. switch ($action) {
  72. case 'cw':
  73. $status->is_nsfw = true;
  74. $status->save();
  75. break;
  76. case 'unlink':
  77. $status->rendered = $status->caption;
  78. $status->save();
  79. break;
  80. case 'unlist':
  81. $status->scope = 'unlisted';
  82. $status->visibility = 'unlisted';
  83. $status->save();
  84. break;
  85. default:
  86. break;
  87. }
  88. } else if ($type == 'profile') {
  89. $profile = Profile::findOrFail($id);
  90. switch ($action) {
  91. case 'delete':
  92. StatusDelete::dispatch($status);
  93. break;
  94. default:
  95. break;
  96. }
  97. }
  98. }
  99. }