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', [ 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 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'); 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; + } + } 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; 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 ]; }