From 588642123eff60b6e8da251b45e9e91b82ae09b5 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 12 Jul 2020 21:27:34 -0600 Subject: [PATCH] Update Api controllers, use MediaPathService --- app/Http/Controllers/Api/ApiV1Controller.php | 12 +++++++----- app/Http/Controllers/Api/BaseApiController.php | 6 ++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/Http/Controllers/Api/ApiV1Controller.php b/app/Http/Controllers/Api/ApiV1Controller.php index edf89261c..dd6112831 100644 --- a/app/Http/Controllers/Api/ApiV1Controller.php +++ b/app/Http/Controllers/Api/ApiV1Controller.php @@ -47,6 +47,7 @@ use App\Jobs\VideoPipeline\{ }; use App\Services\{ NotificationService, + MediaPathService, SearchApiV2Service }; @@ -646,6 +647,10 @@ class ApiV1Controller extends Controller $profile = Profile::findOrFail($id); + if($profile->user->is_admin == true) { + abort(400, 'You cannot block an admin'); + } + Follower::whereProfileId($profile->id)->whereFollowingId($pid)->delete(); Follower::whereProfileId($pid)->whereFollowingId($profile->id)->delete(); Notification::whereProfileId($pid)->whereActorId($profile->id)->delete(); @@ -1030,9 +1035,6 @@ class ApiV1Controller extends Controller $filterClass = in_array($request->input('filter_class'), Filter::classes()) ? $request->input('filter_class') : null; $filterName = in_array($request->input('filter_name'), Filter::names()) ? $request->input('filter_name') : null; - $monthHash = hash('sha1', date('Y').date('m')); - $userHash = hash('sha1', $user->id . (string) $user->created_at); - $photo = $request->file('file'); $mimes = explode(',', config('pixelfed.media_types')); @@ -1040,7 +1042,7 @@ class ApiV1Controller extends Controller abort(403, 'Invalid or unsupported mime type.'); } - $storagePath = "public/m/{$monthHash}/{$userHash}"; + $storagePath = MediaPathService::get($user, 2); $path = $photo->store($storagePath); $hash = \hash_file('sha256', $photo); @@ -1916,7 +1918,7 @@ class ApiV1Controller extends Controller foreach($bookmarks as $id) { $res[] = \App\Services\StatusService::get($id); } - return response()->json($res, 200, [], JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES); + return $res; } /** diff --git a/app/Http/Controllers/Api/BaseApiController.php b/app/Http/Controllers/Api/BaseApiController.php index 6b18f8358..433841fbf 100644 --- a/app/Http/Controllers/Api/BaseApiController.php +++ b/app/Http/Controllers/Api/BaseApiController.php @@ -35,6 +35,7 @@ use App\Jobs\VideoPipeline\{ VideoThumbnail }; use App\Services\NotificationService; +use App\Services\MediaPathService; class BaseApiController extends Controller { @@ -235,9 +236,6 @@ class BaseApiController extends Controller $filterClass = in_array($request->input('filter_class'), Filter::classes()) ? $request->input('filter_class') : null; $filterName = in_array($request->input('filter_name'), Filter::names()) ? $request->input('filter_name') : null; - $monthHash = hash('sha1', date('Y').date('m')); - $userHash = hash('sha1', $user->id . (string) $user->created_at); - $photo = $request->file('file'); $mimes = explode(',', config('pixelfed.media_types')); @@ -245,7 +243,7 @@ class BaseApiController extends Controller return; } - $storagePath = "public/m/{$monthHash}/{$userHash}"; + $storagePath = MediaPathService::get($user, 2); $path = $photo->store($storagePath); $hash = \hash_file('sha256', $photo);