From 480394f3d876af0f1e10db35db8390b3e9d56f64 Mon Sep 17 00:00:00 2001 From: David Gabriel Date: Sat, 9 Sep 2023 19:50:45 +0200 Subject: [PATCH 1/6] [Bugfix] Fix for #4518: SQL query that generates the report list in the admin view needs to include the 'id' field --- app/Http/Controllers/Admin/AdminReportController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/Admin/AdminReportController.php b/app/Http/Controllers/Admin/AdminReportController.php index 4924acfa8..311eac220 100644 --- a/app/Http/Controllers/Admin/AdminReportController.php +++ b/app/Http/Controllers/Admin/AdminReportController.php @@ -643,7 +643,7 @@ trait AdminReportController $q->whereNull('admin_seen') : $q->whereNotNull('admin_seen'); }) - ->groupBy(['object_id', 'object_type']) + ->groupBy(['id', 'object_id', 'object_type']) ->cursorPaginate(6) ->withQueryString() ); From 2e5c141724a78fb9de1a6b2bce947f8e27506703 Mon Sep 17 00:00:00 2001 From: David Gabriel Date: Sat, 9 Sep 2023 20:46:50 +0200 Subject: [PATCH 2/6] Fix similar SQL error which triggers when mentioning people in new posts --- app/Http/Controllers/ComposeController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/ComposeController.php b/app/Http/Controllers/ComposeController.php index 54526ffe8..9be50f346 100644 --- a/app/Http/Controllers/ComposeController.php +++ b/app/Http/Controllers/ComposeController.php @@ -415,7 +415,7 @@ class ComposeController extends Controller $results = Profile::select('id','domain','username') ->whereNotIn('id', $blocked) ->where('username','like','%'.$q.'%') - ->groupBy('domain') + ->groupBy('id', 'domain') ->limit(15) ->get() ->map(function($profile) { From 74ad26fee64a99c8e37c14ab5c69956ada4edb68 Mon Sep 17 00:00:00 2001 From: Emelia Smith Date: Sat, 9 Sep 2023 22:54:11 +0200 Subject: [PATCH 3/6] Fix potential memory leak due to not calling imagedestroy on GdImage objects --- app/Services/InstanceService.php | 3 +++ app/Util/Media/Blurhash.php | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/Services/InstanceService.php b/app/Services/InstanceService.php index 1cead8d48..2ad991063 100644 --- a/app/Services/InstanceService.php +++ b/app/Services/InstanceService.php @@ -120,6 +120,9 @@ class InstanceService $pixels[] = $row; } + // Free the allocated GdImage object from memory: + imagedestroy($image); + $components_x = 4; $components_y = 4; $blurhash = Blurhash::encode($pixels, $components_x, $components_y); diff --git a/app/Util/Media/Blurhash.php b/app/Util/Media/Blurhash.php index c0cca59b9..8e232ea17 100644 --- a/app/Util/Media/Blurhash.php +++ b/app/Util/Media/Blurhash.php @@ -44,6 +44,9 @@ class Blurhash { $pixels[] = $row; } + // Free the allocated GdImage object from memory: + imagedestroy($image); + $components_x = 4; $components_y = 4; $blurhash = BlurhashEngine::encode($pixels, $components_x, $components_y); @@ -53,4 +56,4 @@ class Blurhash { return $blurhash; } -} \ No newline at end of file +} From 941736ce6c29b657c3e7bed831b78d698b720fe4 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 10 Sep 2023 01:12:27 -0600 Subject: [PATCH 4/6] Update StoryApiV1Controller, add viewers route to view story viewers --- .../Stories/StoryApiV1Controller.php | 23 +++++++++++++++++++ app/Http/Resources/StoryView.php | 20 ++++++++++++++++ app/Http/Resources/StoryViewerResource.php | 20 ++++++++++++++++ routes/api.php | 1 + 4 files changed, 64 insertions(+) create mode 100644 app/Http/Resources/StoryView.php create mode 100644 app/Http/Resources/StoryViewerResource.php diff --git a/app/Http/Controllers/Stories/StoryApiV1Controller.php b/app/Http/Controllers/Stories/StoryApiV1Controller.php index e32fffa26..db2b1f533 100644 --- a/app/Http/Controllers/Stories/StoryApiV1Controller.php +++ b/app/Http/Controllers/Stories/StoryApiV1Controller.php @@ -20,6 +20,7 @@ use App\Jobs\StoryPipeline\StoryViewDeliver; use App\Services\AccountService; use App\Services\MediaPathService; use App\Services\StoryService; +use App\Http\Resources\StoryView as StoryViewResource; class StoryApiV1Controller extends Controller { @@ -355,4 +356,26 @@ class StoryApiV1Controller extends Controller $path = $photo->storePubliclyAs($storagePath, Str::random(random_int(2, 12)) . '_' . Str::random(random_int(32, 35)) . '_' . Str::random(random_int(1, 14)) . '.' . $photo->extension()); return $path; } + + public function viewers(Request $request) + { + abort_if(!config_cache('instance.stories.enabled') || !$request->user(), 404); + + $this->validate($request, [ + 'sid' => 'required|string|min:1|max:50' + ]); + + $pid = $request->user()->profile_id; + $sid = $request->input('sid'); + + $story = Story::whereProfileId($pid) + ->whereActive(true) + ->findOrFail($sid); + + $viewers = StoryView::whereStoryId($story->id) + ->orderByDesc('id') + ->cursorPaginate(10); + + return StoryViewResource::collection($viewers); + } } diff --git a/app/Http/Resources/StoryView.php b/app/Http/Resources/StoryView.php new file mode 100644 index 000000000..891bf2eee --- /dev/null +++ b/app/Http/Resources/StoryView.php @@ -0,0 +1,20 @@ + + */ + public function toArray(Request $request) + { + return AccountService::get($this->profile_id, true); + } +} diff --git a/app/Http/Resources/StoryViewerResource.php b/app/Http/Resources/StoryViewerResource.php new file mode 100644 index 000000000..8cae091bd --- /dev/null +++ b/app/Http/Resources/StoryViewerResource.php @@ -0,0 +1,20 @@ + + */ + public function toArray(Request $request): array + { + return AccountService::get($this->profile_id, false); + } +} diff --git a/routes/api.php b/routes/api.php index f305f277c..23abfc323 100644 --- a/routes/api.php +++ b/routes/api.php @@ -316,6 +316,7 @@ Route::group(['prefix' => 'api'], function() use($middleware) { Route::post('seen', 'Stories\StoryApiV1Controller@viewed')->middleware($middleware); Route::post('self-expire/{id}', 'Stories\StoryApiV1Controller@delete')->middleware($middleware); Route::post('comment', 'Stories\StoryApiV1Controller@comment')->middleware($middleware); + Route::get('viewers', 'Stories\StoryApiV1Controller@viewers')->middleware($middleware); }); }); }); From 8fa2afe016e7684daf414fecec158ce6ac076243 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 10 Sep 2023 01:13:45 -0600 Subject: [PATCH 5/6] Remove unused resource --- app/Http/Resources/StoryViewerResource.php | 20 -------------------- 1 file changed, 20 deletions(-) delete mode 100644 app/Http/Resources/StoryViewerResource.php diff --git a/app/Http/Resources/StoryViewerResource.php b/app/Http/Resources/StoryViewerResource.php deleted file mode 100644 index 8cae091bd..000000000 --- a/app/Http/Resources/StoryViewerResource.php +++ /dev/null @@ -1,20 +0,0 @@ - - */ - public function toArray(Request $request): array - { - return AccountService::get($this->profile_id, false); - } -} From 3979e33b5741128723e2c4e1d6b32cf236c7f45c Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 10 Sep 2023 01:14:08 -0600 Subject: [PATCH 6/6] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bc4c890df..45f5a80de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ ### Updates - Update FollowerService, add forget method to RelationshipService call to reduce load when mass purging ([347e4f59](https://github.com/pixelfed/pixelfed/commit/347e4f59)) - Update FollowServiceWarmCache, improve handling larger following/follower lists ([61a6d904](https://github.com/pixelfed/pixelfed/commit/61a6d904)) +- Update StoryApiV1Controller, add viewers route to view story viewers ([941736ce](https://github.com/pixelfed/pixelfed/commit/941736ce)) - ([](https://github.com/pixelfed/pixelfed/commit/)) ## [v0.11.9 (2023-08-21)](https://github.com/pixelfed/pixelfed/compare/v0.11.8...v0.11.9)