From 048642beadd94fe605a2fa92a3e3bf50dc485092 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Thu, 10 Dec 2020 01:02:56 -0700 Subject: [PATCH] Update Collections, add custom limit --- app/Http/Controllers/CollectionController.php | 7 ++++--- app/Util/Site/Config.php | 4 +++- config/pixelfed.php | 1 + resources/assets/js/components/CollectionComponent.vue | 3 ++- resources/assets/js/components/CollectionCompose.vue | 3 ++- resources/assets/js/components/Timeline.vue | 2 +- 6 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/CollectionController.php b/app/Http/Controllers/CollectionController.php index e8354367f..b1d072ff9 100644 --- a/app/Http/Controllers/CollectionController.php +++ b/app/Http/Controllers/CollectionController.php @@ -121,8 +121,9 @@ class CollectionController extends Controller $collection = Collection::whereProfileId($profileId)->findOrFail($collectionId); $count = $collection->items()->count(); - if($count >= 50) { - abort(400, 'You can only add 50 posts per collection'); + $max = config('pixelfed.max_collection_length'); + if($count >= $max) { + abort(400, 'You can only add '.$max.' posts per collection'); } $status = Status::whereScope('public') @@ -165,7 +166,7 @@ class CollectionController extends Controller if($collection->visibility !== 'public') { abort_if(!Auth::check() || Auth::user()->profile_id != $collection->profile_id, 404); } - $posts = $collection->posts()->orderBy('order', 'asc')->paginate(18); + $posts = $collection->posts()->orderBy('order', 'asc')->get(); $fractal = new Fractal\Manager(); $fractal->setSerializer(new ArraySerializer()); diff --git a/app/Util/Site/Config.php b/app/Util/Site/Config.php index 8304b73e2..b59b610f0 100644 --- a/app/Util/Site/Config.php +++ b/app/Util/Site/Config.php @@ -8,7 +8,7 @@ use Illuminate\Support\Str; class Config { public static function get() { - return Cache::remember('api:site:configuration', now()->addMinutes(30), function() { + return Cache::remember('api:site:configuration:_v0', now()->addHours(30), function() { return [ 'open_registration' => config('pixelfed.open_registration'), 'uploader' => [ @@ -17,6 +17,8 @@ class Config { 'album_limit' => config('pixelfed.max_album_length'), 'image_quality' => config('pixelfed.image_quality'), + 'max_collection_length' => config('pixelfed.max_collection_length', 18), + 'optimize_image' => config('pixelfed.optimize_image'), 'optimize_video' => config('pixelfed.optimize_video'), diff --git a/config/pixelfed.php b/config/pixelfed.php index cf2935b3e..9df6bc99c 100644 --- a/config/pixelfed.php +++ b/config/pixelfed.php @@ -239,6 +239,7 @@ return [ ] ], + 'max_collection_length' => (int) env('PF_MAX_COLLECTION_LENGTH', 18), 'media_types' => env('MEDIA_TYPES', 'image/jpeg,image/png,image/gif'), diff --git a/resources/assets/js/components/CollectionComponent.vue b/resources/assets/js/components/CollectionComponent.vue index 559f7447b..904471861 100644 --- a/resources/assets/js/components/CollectionComponent.vue +++ b/resources/assets/js/components/CollectionComponent.vue @@ -161,6 +161,7 @@ export default { data() { return { + config: window.App.config, loaded: false, posts: [], ids: [], @@ -243,7 +244,7 @@ export default { }, pushId() { - let max = 18; + let max = this.config.uploader.max_collection_length; let addingPostToCollection = true; let self = this; if(this.posts.length >= max) { diff --git a/resources/assets/js/components/CollectionCompose.vue b/resources/assets/js/components/CollectionCompose.vue index e6556af75..91115b5ee 100644 --- a/resources/assets/js/components/CollectionCompose.vue +++ b/resources/assets/js/components/CollectionCompose.vue @@ -113,6 +113,7 @@ export default { props: ['collection-id', 'profile-id'], data() { return { + config: window.App.config, loaded: false, limit: 8, step: 1, @@ -175,7 +176,7 @@ export default { }, addId() { - let max = 18; + let max = this.config.uploader.max_collection_length; if(this.posts.length >= max) { swal('Error', 'You can only add ' + max + ' posts per collection', 'error'); return; diff --git a/resources/assets/js/components/Timeline.vue b/resources/assets/js/components/Timeline.vue index 803c5c969..8e102feb0 100644 --- a/resources/assets/js/components/Timeline.vue +++ b/resources/assets/js/components/Timeline.vue @@ -345,7 +345,7 @@