From 820233adb13155f4df7925ff7942f2954c50b70c Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Mon, 19 Aug 2019 19:04:40 -0600 Subject: [PATCH 1/6] Update InternalApiController, add places --- app/Http/Controllers/InternalApiController.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/InternalApiController.php b/app/Http/Controllers/InternalApiController.php index f6ddff916..abe07ad22 100644 --- a/app/Http/Controllers/InternalApiController.php +++ b/app/Http/Controllers/InternalApiController.php @@ -239,7 +239,8 @@ class InternalApiController extends Controller 'media.*.filter_class' => 'nullable|alpha_dash|max:30', 'media.*.license' => 'nullable|string|max:80', 'cw' => 'nullable|boolean', - 'visibility' => 'required|string|in:public,private,unlisted|min:2|max:10' + 'visibility' => 'required|string|in:public,private,unlisted|min:2|max:10', + 'place' => 'nullable' ]); if(config('costar.enabled') == true) { @@ -283,6 +284,9 @@ class InternalApiController extends Controller array_push($mimes, $m->mime); } + if($request->filled('place')) { + $status->place_id = $request->input('place')['id']; + } $status->caption = strip_tags($request->caption); $status->scope = 'draft'; $status->profile_id = $profile->id; From 2a42a1c02ec6586b9d933b700d1f7a8ea14e8a4b Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Mon, 19 Aug 2019 19:06:22 -0600 Subject: [PATCH 2/6] Update BaseApiController --- app/Http/Controllers/Api/BaseApiController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/Api/BaseApiController.php b/app/Http/Controllers/Api/BaseApiController.php index 491287398..eb92a1806 100644 --- a/app/Http/Controllers/Api/BaseApiController.php +++ b/app/Http/Controllers/Api/BaseApiController.php @@ -227,7 +227,7 @@ class BaseApiController extends Controller } $monthHash = hash('sha1', date('Y').date('m')); - $userHash = hash('sha1', $user->id.(string) $user->created_at); + $userHash = hash('sha1', $user->id . (string) $user->created_at); $photo = $request->file('file'); From 32d7ab091df8d389b2cd6b9fee2796ed943c9238 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Mon, 19 Aug 2019 19:07:25 -0600 Subject: [PATCH 3/6] Add AdminApiController --- .../Controllers/Api/AdminApiController.php | 116 ++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 app/Http/Controllers/Api/AdminApiController.php diff --git a/app/Http/Controllers/Api/AdminApiController.php b/app/Http/Controllers/Api/AdminApiController.php new file mode 100644 index 000000000..dfacf47ee --- /dev/null +++ b/app/Http/Controllers/Api/AdminApiController.php @@ -0,0 +1,116 @@ +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) + { + $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; + } + } + + } + +} \ No newline at end of file From 460433ff208b6d8c50f9f94a21dc03dff7ad2720 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Mon, 19 Aug 2019 19:09:56 -0600 Subject: [PATCH 4/6] Update ApiController --- app/Http/Controllers/ApiController.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/app/Http/Controllers/ApiController.php b/app/Http/Controllers/ApiController.php index 16f906161..6903b3d41 100644 --- a/app/Http/Controllers/ApiController.php +++ b/app/Http/Controllers/ApiController.php @@ -6,6 +6,7 @@ use App\Http\Controllers\Api\BaseApiController; use App\{ Follower, Like, + Place, Profile, UserFilter }; @@ -78,4 +79,24 @@ class ApiController extends BaseApiController return response()->json($res->all()); } + public function composeLocationSearch(Request $request) + { + $this->validate($request, [ + 'q' => 'required|string' + ]); + + $places = Place::where('name', 'like', '%' . $request->input('q') . '%') + ->take(25) + ->get() + ->map(function($r) { + return [ + 'id' => $r->id, + 'name' => $r->name, + 'country' => $r->country, + 'url' => $r->url() + ]; + }); + return $places; + } + } From bd05f63deccb4e5ff5d54296dc97592ef8781efd Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Mon, 19 Aug 2019 19:16:48 -0600 Subject: [PATCH 5/6] Update StatusTransformer, add place --- app/Transformer/Api/StatusTransformer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Transformer/Api/StatusTransformer.php b/app/Transformer/Api/StatusTransformer.php index 83773a47c..27f3f555f 100644 --- a/app/Transformer/Api/StatusTransformer.php +++ b/app/Transformer/Api/StatusTransformer.php @@ -47,7 +47,7 @@ class StatusTransformer extends Fractal\TransformerAbstract 'thread' => false, 'replies' => [], 'parent' => [], - //'place' => $status->place + 'place' => $status->place ]; } From 9524ea19f55d4b4f9f5975fc42de9ad167f9cdf4 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 20 Aug 2019 22:22:25 -0600 Subject: [PATCH 6/6] Update media:optimize command --- app/Console/Commands/CatchUnoptimizedMedia.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Console/Commands/CatchUnoptimizedMedia.php b/app/Console/Commands/CatchUnoptimizedMedia.php index 1072c45d6..6b3c3547d 100644 --- a/app/Console/Commands/CatchUnoptimizedMedia.php +++ b/app/Console/Commands/CatchUnoptimizedMedia.php @@ -42,6 +42,7 @@ class CatchUnoptimizedMedia extends Command { DB::transaction(function() { Media::whereNull('processed_at') + ->whereNull('remote_url') ->whereNotNull('status_id') ->whereNotNull('media_path') ->whereIn('mime', [