From 2281727ac035bfd09753bab685ba3ba8033e7c86 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 30 Jan 2021 19:45:02 -0700 Subject: [PATCH 1/9] Update nav partial --- resources/views/layouts/partial/nav.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/layouts/partial/nav.blade.php b/resources/views/layouts/partial/nav.blade.php index 9f336327a..28e1a28d0 100644 --- a/resources/views/layouts/partial/nav.blade.php +++ b/resources/views/layouts/partial/nav.blade.php @@ -52,7 +52,7 @@ From 090b6d033626438fd1748620909e986743460326 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 30 Jan 2021 19:56:10 -0700 Subject: [PATCH 2/9] Update SeasonalController --- app/Http/Controllers/SeasonalController.php | 25 +++++++++++---------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/app/Http/Controllers/SeasonalController.php b/app/Http/Controllers/SeasonalController.php index d1077276d..a9f1f98cb 100644 --- a/app/Http/Controllers/SeasonalController.php +++ b/app/Http/Controllers/SeasonalController.php @@ -219,20 +219,21 @@ class SeasonalController extends Controller { abort_if(now()->gt('2021-03-01 00:00:00'), 404); abort_if(config('database.default') != 'mysql', 404); - $this->validate($request, [ - 'profile_id' => 'required', - 'type' => 'required|string|in:view,hide' - ]); $user = $request->user(); - $log = new AccountLog(); - $log->user_id = $user->id; - $log->item_type = 'App\User'; - $log->item_id = $user->id; - $log->action = $request->input('type') == 'view' ? 'seasonal.my2020.view' : 'seasonal.my2020.hide'; - $log->ip_address = $request->ip(); - $log->user_agent = $request->user_agent(); - $log->save(); + $log = AccountLog::firstOrCreate([ + [ + 'item_type' => 'App\User', + 'item_id' => $user->id, + 'user_id' => $user->id, + 'action' => 'seasonal.my2020.view' + ], + [ + 'ip_address' => $request->ip(), + 'user_agent' => $request->userAgent() + ] + ]); + return response()->json(200); } } From 1ac60173af34d397df2b227574e380c97327c117 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 30 Jan 2021 19:56:31 -0700 Subject: [PATCH 3/9] Update AccountLog model, add fillable attribute --- app/AccountLog.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/AccountLog.php b/app/AccountLog.php index 3f7521f3b..039accb90 100644 --- a/app/AccountLog.php +++ b/app/AccountLog.php @@ -6,6 +6,9 @@ use Illuminate\Database\Eloquent\Model; class AccountLog extends Model { + + protected $fillable = ['*']; + public function user() { return $this->belongsTo(User::class); From 9862a855996657236f060bf13b09dbad53ae8056 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 30 Jan 2021 21:39:31 -0700 Subject: [PATCH 4/9] Update InternalApiController, update discoverPosts method to improve performance --- .../Controllers/InternalApiController.php | 132 +----------------- 1 file changed, 7 insertions(+), 125 deletions(-) diff --git a/app/Http/Controllers/InternalApiController.php b/app/Http/Controllers/InternalApiController.php index e3fc8c757..1a0af7d1a 100644 --- a/app/Http/Controllers/InternalApiController.php +++ b/app/Http/Controllers/InternalApiController.php @@ -35,6 +35,8 @@ use Illuminate\Support\Str; use App\Services\MediaTagService; use App\Services\ModLogService; use App\Services\PublicTimelineService; +use App\Services\SnowflakeService; +use App\Services\StatusService; class InternalApiController extends Controller { @@ -82,37 +84,27 @@ class InternalApiController extends Controller $following = array_merge($following, $filters); $sql = config('database.default') !== 'pgsql'; - + $min_id = SnowflakeService::byDate(now()->subMonths(3)); $posts = Status::select( 'id', - 'caption', 'is_nsfw', 'profile_id', 'type', 'uri', - 'created_at' ) ->whereNull('uri') ->whereIn('type', ['photo','photo:album', 'video']) ->whereIsNsfw(false) ->whereVisibility('public') ->whereNotIn('profile_id', $following) - ->when($sql, function($q, $s) { - return $q->where('created_at', '>', now()->subMonths(3)); - }) - ->with('media') + ->where('id', '>', $min_id) ->inRandomOrder() - ->latest() ->take(39) - ->get(); + ->pluck('id'); $res = [ 'posts' => $posts->map(function($post) { - return [ - 'type' => $post->type, - 'url' => $post->url(), - 'thumb' => $post->thumb(), - ]; + return StatusService::get($post); }) ]; return response()->json($res); @@ -323,117 +315,7 @@ class InternalApiController extends Controller public function composePost(Request $request) { - $this->validate($request, [ - 'caption' => 'nullable|string|max:'.config('pixelfed.max_caption_length', 500), - 'media.*' => 'required', - 'media.*.id' => 'required|integer|min:1', - 'media.*.filter_class' => 'nullable|alpha_dash|max:30', - 'media.*.license' => 'nullable|string|max:140', - 'media.*.alt' => 'nullable|string|max:140', - 'cw' => 'nullable|boolean', - 'visibility' => 'required|string|in:public,private,unlisted|min:2|max:10', - 'place' => 'nullable', - 'comments_disabled' => 'nullable', - 'tagged' => 'nullable' - ]); - - if(config('costar.enabled') == true) { - $blockedKeywords = config('costar.keyword.block'); - if($blockedKeywords !== null && $request->caption) { - $keywords = config('costar.keyword.block'); - foreach($keywords as $kw) { - if(Str::contains($request->caption, $kw) == true) { - abort(400, 'Invalid object'); - } - } - } - } - - $user = Auth::user(); - $profile = $user->profile; - $visibility = $request->input('visibility'); - $medias = $request->input('media'); - $attachments = []; - $status = new Status; - $mimes = []; - $place = $request->input('place'); - $cw = $request->input('cw'); - $tagged = $request->input('tagged'); - - foreach($medias as $k => $media) { - if($k + 1 > config('pixelfed.max_album_length')) { - continue; - } - $m = Media::findOrFail($media['id']); - if($m->profile_id !== $profile->id || $m->status_id) { - abort(403, 'Invalid media id'); - } - $m->filter_class = in_array($media['filter_class'], Filter::classes()) ? $media['filter_class'] : null; - $m->license = $media['license']; - $m->caption = isset($media['alt']) ? strip_tags($media['alt']) : null; - $m->order = isset($media['cursor']) && is_int($media['cursor']) ? (int) $media['cursor'] : $k; - if($cw == true || $profile->cw == true) { - $m->is_nsfw = $cw; - $status->is_nsfw = $cw; - } - $m->save(); - $attachments[] = $m; - array_push($mimes, $m->mime); - } - - $mediaType = StatusController::mimeTypeCheck($mimes); - - if(in_array($mediaType, ['photo', 'video', 'photo:album']) == false) { - abort(400, __('exception.compose.invalid.album')); - } - - if($place && is_array($place)) { - $status->place_id = $place['id']; - } - - if($request->filled('comments_disabled')) { - $status->comments_disabled = (bool) $request->input('comments_disabled'); - } - - $status->caption = strip_tags($request->caption); - $status->scope = 'draft'; - $status->profile_id = $profile->id; - $status->save(); - - foreach($attachments as $media) { - $media->status_id = $status->id; - $media->save(); - } - - $visibility = $profile->unlisted == true && $visibility == 'public' ? 'unlisted' : $visibility; - $cw = $profile->cw == true ? true : $cw; - $status->is_nsfw = $cw; - $status->visibility = $visibility; - $status->scope = $visibility; - $status->type = $mediaType; - $status->save(); - - foreach($tagged as $tg) { - $mt = new MediaTag; - $mt->status_id = $status->id; - $mt->media_id = $status->media->first()->id; - $mt->profile_id = $tg['id']; - $mt->tagged_username = $tg['name']; - $mt->is_public = true; // (bool) $tg['privacy'] ?? 1; - $mt->metadata = json_encode([ - '_v' => 1, - ]); - $mt->save(); - MediaTagService::set($mt->status_id, $mt->profile_id); - MediaTagService::sendNotification($mt); - } - - NewStatusPipeline::dispatch($status); - Cache::forget('user:account:id:'.$profile->user_id); - Cache::forget('_api:statuses:recent_9:'.$profile->id); - Cache::forget('profile:status_count:'.$profile->id); - Cache::forget($user->storageUsedKey()); - return $status->url(); + abort(400, 'Endpoint deprecated'); } public function bookmarks(Request $request) From a8ebdd2e399dcbefbade8e76619912923589f5b0 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 30 Jan 2021 21:56:50 -0700 Subject: [PATCH 5/9] Update DiscoverComponent, add blurhash and like/comment counts --- .../js/components/DiscoverComponent.vue | 94 ++++++++++++++++--- 1 file changed, 82 insertions(+), 12 deletions(-) diff --git a/resources/assets/js/components/DiscoverComponent.vue b/resources/assets/js/components/DiscoverComponent.vue index 6ad5cd537..69140e672 100644 --- a/resources/assets/js/components/DiscoverComponent.vue +++ b/resources/assets/js/components/DiscoverComponent.vue @@ -39,13 +39,46 @@
-
- +
-
- +
+
- - - -
+
+
+
+ + + +
+
+ +
+
+ + +
+ + + +
+
+ + + {{formatCount(s.favourites_count)}} + + + + {{formatCount(s.reply_count)}} + +
@@ -314,6 +380,10 @@ .then(res => { this.places = res.data; }); + }, + + formatCount(s) { + return App.util.format.count(s); } } } From 7075b7f83eadbff9564d064e500e34d26f3a72a2 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 30 Jan 2021 21:58:37 -0700 Subject: [PATCH 6/9] Update compiled assets --- public/js/discover.js | Bin 16218 -> 18221 bytes public/mix-manifest.json | Bin 2139 -> 2139 bytes 2 files changed, 0 insertions(+), 0 deletions(-) diff --git a/public/js/discover.js b/public/js/discover.js index fd516e6ca7db47732afd13bb67f7eb6075da433b..9ee5cab919e90721ff2f4cf569e4ed7e0bdb1089 100644 GIT binary patch delta 2995 zcmeHJL2MgE6xF6lo2F3%Rly}{9cNL)E}q@kNn@qnY)mjhMToXk2->=fHSvzKgVwv- zow1wXy6FKSB&3LH1SbTiN^k%Hz5o)4N)#cua6qU+aH_ae;=~mYe{3g&wxEJ~;80l_ zeb4@R^XC6Q^WXR9-dR&#c}bk;(*|<0N0};4??{d{aGYXxpsBf|IbYSSzzj5|o4AEK zGvX5?F(^NuIOaYozL-Y}7Qf6NgwZIBw^#d4DqAq3;)g94XQ^J`c@5hc+qS7m1D7lx zscP!vq^cKa{`y&%4AL~u(o}rZp9Z|2`oD$oALVMHEtZPmpb8x2E+)BHU6SwEhb zz~cSwr*?y(`F2>S)`JSCVW8S?AO@yM7QAaMZZoYPAryHJLh@O&x*t_#ro~>N=wKk;Ugog=@I|`mWf`oPST(n8exOPK3*|6S>|e& zmNx@T7{{Deiaus6ugZ_c8IN+3su{S>!&Eg4V5SodV=?sI-clCfKt&~yOzz1-kyf$c z5gc=A_)DqCm`b@u)hEja4SX69wY513uqyG)b>BPrYG{xt2E(SZ(TG{ajj$dADOT+J^n5azT7(?CZ4KD~3BD+b9+b=BR?(r_4Z6 zJn{9UVPTt=m`Pp7qE!t;Yc*q1W$Cmfo4nKoF*N#k4x14?yBn$@2GxMYbSATN{Xms8GY{`7Ypm;CiXB9B-J;@hCM~|2ynD6eAZ9mZ&%L>N01*P}0mU{k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--- .../views/layouts/partial/footer.blade.php | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/resources/views/layouts/partial/footer.blade.php b/resources/views/layouts/partial/footer.blade.php index 24e3fe322..86ef1de02 100644 --- a/resources/views/layouts/partial/footer.blade.php +++ b/resources/views/layouts/partial/footer.blade.php @@ -1,17 +1,19 @@ @if(config('instance.restricted.enabled') == false) From eadf0c3b6c9e824af5b4df50c610d96fe5ee01fd Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 30 Jan 2021 22:15:54 -0700 Subject: [PATCH 8/9] Update nav partial --- resources/views/layouts/partial/nav.blade.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/resources/views/layouts/partial/nav.blade.php b/resources/views/layouts/partial/nav.blade.php index 28e1a28d0..79f498e8b 100644 --- a/resources/views/layouts/partial/nav.blade.php +++ b/resources/views/layouts/partial/nav.blade.php @@ -18,16 +18,16 @@