AdminApiController.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. abort(400, 'Unpublished API');
  62. return;
  63. $this->validate($request, [
  64. 'type' => 'required|string|in:status,profile',
  65. 'id' => 'required|integer|min:1',
  66. 'action' => 'required|string|in:cw,unlink,unlist,suspend,delete'
  67. ]);
  68. $type = $request->input('type');
  69. $id = $request->input('id');
  70. $action = $request->input('action');
  71. if ($type == 'status') {
  72. $status = Status::findOrFail($id);
  73. switch ($action) {
  74. case 'cw':
  75. $status->is_nsfw = true;
  76. $status->save();
  77. break;
  78. case 'unlink':
  79. $status->rendered = $status->caption;
  80. $status->save();
  81. break;
  82. case 'unlist':
  83. $status->scope = 'unlisted';
  84. $status->visibility = 'unlisted';
  85. $status->save();
  86. break;
  87. default:
  88. break;
  89. }
  90. } else if ($type == 'profile') {
  91. $profile = Profile::findOrFail($id);
  92. switch ($action) {
  93. case 'delete':
  94. StatusDelete::dispatch($status);
  95. break;
  96. default:
  97. break;
  98. }
  99. }
  100. }
  101. }