From c5e84cbbf9bff653389e6318ad0be1158132894d Mon Sep 17 00:00:00 2001 From: Matthias Gutjahr Date: Thu, 27 Dec 2018 18:47:35 +0100 Subject: [PATCH 001/108] Add required PHP extensions to composer.json Signed-off-by: Matthias Gutjahr --- composer.json | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/composer.json b/composer.json index 77185550..e2738cb6 100644 --- a/composer.json +++ b/composer.json @@ -6,6 +6,13 @@ "type": "project", "require": { "php": "^7.1.3", + "ext-bcmath": "*", + "ext-ctype": "*", + "ext-curl": "*", + "ext-json": "*", + "ext-mbstring": "*", + "ext-openssl": "*", + "ext-redis": "*", "beyondcode/laravel-self-diagnosis": "^1.0.2", "bitverse/identicon": "^1.1", "doctrine/dbal": "^2.7", From ebbe8424165caf984f38608debbadbd9f3536a15 Mon Sep 17 00:00:00 2001 From: Carly Ho Date: Sat, 29 Dec 2018 16:55:47 -0600 Subject: [PATCH 002/108] Add confirmation check to post deletion function --- .../assets/js/components/PostComponent.vue | 45 ++++++++++--------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/resources/assets/js/components/PostComponent.vue b/resources/assets/js/components/PostComponent.vue index c3b9f625..cf6665a9 100644 --- a/resources/assets/js/components/PostComponent.vue +++ b/resources/assets/js/components/PostComponent.vue @@ -56,11 +56,11 @@
-
+
- +
@@ -164,10 +164,10 @@
-
@@ -195,10 +195,10 @@
-
@@ -281,7 +281,7 @@ export default { $('head title').text(title); } }, - + methods: { authCheck() { let authed = $('body').hasClass('loggedIn'); @@ -495,19 +495,22 @@ export default { }, deletePost() { - if($('body').hasClass('loggedIn') == false) { - return; - } + var result = confirm('Are you sure you want to delete this post?'); + if (result) { + if($('body').hasClass('loggedIn') == false) { + return; + } - axios.post('/i/delete', { - type: 'status', - item: this.status.id - }).then(res => { - swal('Success', 'You have successfully deleted this post', 'success'); - }).catch(err => { - swal('Error', 'Something went wrong. Please try again later.', 'error'); - }); + axios.post('/i/delete', { + type: 'status', + item: this.status.id + }).then(res => { + swal('Success', 'You have successfully deleted this post', 'success'); + }).catch(err => { + swal('Error', 'Something went wrong. Please try again later.', 'error'); + }); + } } } } - \ No newline at end of file + From 327dd891779cff983b05a16a290f507e505b7c1f Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 29 Dec 2018 22:36:16 -0700 Subject: [PATCH 003/108] Update PostComments, fix comment order --- resources/assets/js/components/PostComments.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/assets/js/components/PostComments.vue b/resources/assets/js/components/PostComments.vue index 6122f0b2..fc9990c1 100644 --- a/resources/assets/js/components/PostComments.vue +++ b/resources/assets/js/components/PostComments.vue @@ -92,7 +92,7 @@ export default { axios.get(url) .then(response => { let self = this; - this.results = response.data.data; + this.results = _.reverse(response.data.data); this.pagination = response.data.meta.pagination; if(this.results.length > 0) { $('.load-more-link').removeClass('d-none'); From 9a3b70d23d2ce8c990c77fc037ea6c7c252e0048 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 29 Dec 2018 22:37:30 -0700 Subject: [PATCH 004/108] Update config --- config/pixelfed.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/config/pixelfed.php b/config/pixelfed.php index feb3ed31..0bd5b94f 100644 --- a/config/pixelfed.php +++ b/config/pixelfed.php @@ -177,6 +177,28 @@ return [ */ 'image_quality' => (int) env('IMAGE_QUALITY', 80), + /* + |-------------------------------------------------------------------------- + | Account deletion + |-------------------------------------------------------------------------- + | + | Enable account deletion. + | + */ + 'account_deletion' => env('ACCOUNT_DELETION', true), + + /* + |-------------------------------------------------------------------------- + | Account deletion after X days + |-------------------------------------------------------------------------- + | + | Set account deletion queue after X days, set to false to delete accounts + | immediately. + | + */ + 'account_delete_after' => env('ACCOUNT_DELETE_AFTER', false), + + 'media_types' => env('MEDIA_TYPES', 'image/jpeg,image/png,image/gif'), 'enforce_account_limit' => env('LIMIT_ACCOUNT_SIZE', true), 'ap_inbox' => env('ACTIVITYPUB_INBOX', false), From 5b68d147d282bb49506da60f1ed58906dee50791 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 29 Dec 2018 22:39:08 -0700 Subject: [PATCH 005/108] Update StatusPipeline, only deliver if ap is enabled --- app/Jobs/StatusPipeline/NewStatusPipeline.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/Jobs/StatusPipeline/NewStatusPipeline.php b/app/Jobs/StatusPipeline/NewStatusPipeline.php index 97322368..efb7d6b1 100644 --- a/app/Jobs/StatusPipeline/NewStatusPipeline.php +++ b/app/Jobs/StatusPipeline/NewStatusPipeline.php @@ -37,7 +37,10 @@ class NewStatusPipeline implements ShouldQueue $status = $this->status; StatusEntityLexer::dispatch($status); - StatusActivityPubDeliver::dispatch($status); + + if(config('pixelfed.activitypub_enabled') == true) { + StatusActivityPubDeliver::dispatch($status); + } // Cache::forever('post.'.$status->id, $status); // $redis = Redis::connection(); From 6f4da63a83cca651b8454051bf2525a028fb4ed3 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 29 Dec 2018 22:39:39 -0700 Subject: [PATCH 006/108] Update SettingsController --- app/Http/Controllers/SettingsController.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php index a4129500..730e0b4e 100644 --- a/app/Http/Controllers/SettingsController.php +++ b/app/Http/Controllers/SettingsController.php @@ -149,11 +149,17 @@ class SettingsController extends Controller public function removeAccountPermanent(Request $request) { + if(config('pixelfed.account_deletion') == false) { + abort(404); + } return view('settings.remove.permanent'); } public function removeAccountPermanentSubmit(Request $request) { + if(config('pixelfed.account_deletion') == false) { + abort(404); + } $user = Auth::user(); if($user->is_admin == true) { return abort(400, 'You cannot delete an admin account.'); From b6757550f23b375e6d945d5c0d58b21279e2a02a Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 29 Dec 2018 22:41:51 -0700 Subject: [PATCH 007/108] Update Help Center --- resources/views/site/help/your-profile.blade.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/resources/views/site/help/your-profile.blade.php b/resources/views/site/help/your-profile.blade.php index 7354585e..4d81698c 100644 --- a/resources/views/site/help/your-profile.blade.php +++ b/resources/views/site/help/your-profile.blade.php @@ -140,7 +140,7 @@

- {{--
+

Delete Your Account

+ @if(config('pixelfed.account_delete_after') == false)
-

When you delete your account, your profile, photos, videos, comments, likes and followers will be permanently removed. If you'd just like to take a break, you can temporarily disable your account instead.

+

When you delete your account, your profile, photos, videos, comments, likes and followers will be permanently removed. If you'd just like to take a break, you can temporarily disable your account instead.

+ @else +
+

When you delete your account, your profile, photos, videos, comments, likes and followers will be permanently removed after {{config('pixelfed.account_delete_after')}} days. You can log in during that period to prevent your account from permanent deletion. If you'd just like to take a break, you can temporarily disable your account instead.

+
+ @endif

After you delete your account, you can't sign up again with the same username on this instance or add that username to another account on this instance, and we can't reactivate deleted accounts.

To permanently delete your account:

    @@ -178,5 +185,6 @@
-

--}} +

+ @endif @endsection \ No newline at end of file From c78686e355b59a93cde3e91a778050a04c27a2a7 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 29 Dec 2018 23:10:14 -0700 Subject: [PATCH 008/108] Add Announce validator and test --- app/Util/ActivityPub/Validator/Announce.php | 28 ++++ tests/Unit/ActivityPub/Verb/AnnounceTest.php | 168 +++++++++++++++++++ 2 files changed, 196 insertions(+) create mode 100644 app/Util/ActivityPub/Validator/Announce.php create mode 100644 tests/Unit/ActivityPub/Verb/AnnounceTest.php diff --git a/app/Util/ActivityPub/Validator/Announce.php b/app/Util/ActivityPub/Validator/Announce.php new file mode 100644 index 00000000..c66fedbb --- /dev/null +++ b/app/Util/ActivityPub/Validator/Announce.php @@ -0,0 +1,28 @@ + 'required', + 'id' => 'required|string', + 'type' => [ + 'required', + Rule::in(['Announce']) + ], + 'actor' => 'required|url|active_url', + 'published' => 'required|date', + 'to' => 'required', + 'cc' => 'required', + 'object' => 'required|url|active_url' + ])->passes(); + + return $valid; + } +} \ No newline at end of file diff --git a/tests/Unit/ActivityPub/Verb/AnnounceTest.php b/tests/Unit/ActivityPub/Verb/AnnounceTest.php new file mode 100644 index 00000000..c3e73969 --- /dev/null +++ b/tests/Unit/ActivityPub/Verb/AnnounceTest.php @@ -0,0 +1,168 @@ +validAnnounce = [ + "@context" => "https://www.w3.org/ns/activitystreams", + "id" => "https://example.org/users/alice/statuses/100000000000001/activity", + "type" => "Announce", + "actor" => "https://example.org/users/alice", + "published" => "2018-12-31T23:59:59Z", + "to" => [ + "https://www.w3.org/ns/activitystreams#Public" + ], + "cc" => [ + "https://example.org/users/bob", + "https://example.org/users/alice/followers" + ], + "object" => "https://example.org/p/bob/100000000000000", + ]; + + $this->invalidAnnounce = [ + "@context" => "https://www.w3.org/ns/activitystreams", + "id" => "https://example.org/users/alice/statuses/100000000000001/activity", + "type" => "Announce2", + "actor" => "https://example.org/users/alice", + "published" => "2018-12-31T23:59:59Z", + "to" => [ + "https://www.w3.org/ns/activitystreams#Public" + ], + "cc" => [ + "https://example.org/users/bob", + "https://example.org/users/alice/followers" + ], + "object" => "https://example.org/p/bob/100000000000000", + ]; + + $this->invalidDate = [ + "@context" => "https://www.w3.org/ns/activitystreams", + "id" => "https://example.org/users/alice/statuses/100000000000001/activity", + "type" => "Announce", + "actor" => "https://example.org/users/alice", + "published" => "2018-12-31T23:59:59ZEZE", + "to" => [ + "https://www.w3.org/ns/activitystreams#Public" + ], + "cc" => [ + "https://example.org/users/bob", + "https://example.org/users/alice/followers" + ], + "object" => "https://example.org/p/bob/100000000000000", + ]; + + $this->contextMissing = [ + "id" => "https://example.org/users/alice/statuses/100000000000001/activity", + "type" => "Announce", + "actor" => "https://example.org/users/alice", + "published" => "2018-12-31T23:59:59Z", + "to" => [ + "https://www.w3.org/ns/activitystreams#Public" + ], + "cc" => [ + "https://example.org/users/bob", + "https://example.org/users/alice/followers" + ], + "object" => "https://example.org/p/bob/100000000000000", + ]; + + $this->audienceMissing = [ + "id" => "https://example.org/users/alice/statuses/100000000000001/activity", + "type" => "Announce", + "actor" => "https://example.org/users/alice", + "published" => "2018-12-31T23:59:59Z", + "object" => "https://example.org/p/bob/100000000000000", + ]; + + $this->audienceMissing2 = [ + "@context" => "https://www.w3.org/ns/activitystreams", + "id" => "https://example.org/users/alice/statuses/100000000000001/activity", + "type" => "Announce", + "actor" => "https://example.org/users/alice", + "published" => "2018-12-31T23:59:59Z", + "to" => null, + "cc" => null, + "object" => "https://example.org/p/bob/100000000000000", + ]; + + $this->invalidActor = [ + "@context" => "https://www.w3.org/ns/activitystreams", + "id" => "https://example.org/users/alice/statuses/100000000000001/activity", + "type" => "Announce", + "actor" => "10000", + "published" => "2018-12-31T23:59:59Z", + "to" => [ + "https://www.w3.org/ns/activitystreams#Public" + ], + "cc" => [ + "https://example.org/users/bob", + "https://example.org/users/alice/followers" + ], + "object" => "https://example.org/p/bob/100000000000000", + ]; + + $this->invalidActor2 = [ + "@context" => "https://www.w3.org/ns/activitystreams", + "id" => "https://example.org/users/alice/statuses/100000000000001/activity", + "type" => "Announce", + "published" => "2018-12-31T23:59:59Z", + "to" => [ + "https://www.w3.org/ns/activitystreams#Public" + ], + "cc" => [ + "https://example.org/users/bob", + "https://example.org/users/alice/followers" + ], + "object" => "https://example.org/p/bob/100000000000000", + ]; + } + + /** @test */ + public function basic_accept() + { + $this->assertTrue(Announce::validate($this->validAnnounce)); + } + + /** @test */ + public function invalid_accept() + { + $this->assertFalse(Announce::validate($this->invalidAnnounce)); + } + + /** @test */ + public function invalid_date() + { + $this->assertFalse(Announce::validate($this->invalidDate)); + } + + /** @test */ + public function context_missing() + { + $this->assertFalse(Announce::validate($this->contextMissing)); + } + + /** @test */ + public function audience_missing() + { + $this->assertFalse(Announce::validate($this->audienceMissing)); + $this->assertFalse(Announce::validate($this->audienceMissing2)); + } + + /** @test */ + public function invalid_actor() + { + $this->assertFalse(Announce::validate($this->invalidActor)); + $this->assertFalse(Announce::validate($this->invalidActor2)); + } +} From 982aecb4cc3984b1ba7f5ca07cc9537ec984ee92 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 30 Dec 2018 13:51:42 -0700 Subject: [PATCH 009/108] Add new migration --- ...update_profiles_table_use_text_for_bio.php | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 database/migrations/2018_12_30_065102_update_profiles_table_use_text_for_bio.php diff --git a/database/migrations/2018_12_30_065102_update_profiles_table_use_text_for_bio.php b/database/migrations/2018_12_30_065102_update_profiles_table_use_text_for_bio.php new file mode 100644 index 00000000..96443631 --- /dev/null +++ b/database/migrations/2018_12_30_065102_update_profiles_table_use_text_for_bio.php @@ -0,0 +1,32 @@ +text('bio')->nullable()->change(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('profiles', function (Blueprint $table) { + $table->string('bio')->nullable()->change(); + }); + } +} From 547ac5c8f9a85585331c1e6e540698aeed8b3798 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 30 Dec 2018 21:26:37 -0700 Subject: [PATCH 010/108] Add/update API transformers --- app/Transformer/Api/AccountTransformer.php | 46 +++++++++---------- .../Api/ApplicationTransformer.php | 14 +++--- app/Transformer/Api/AttachmentTransformer.php | 28 +++++++++++ app/Transformer/Api/ContextTransformer.php | 16 +++++++ app/Transformer/Api/EmojiTransformer.php | 18 ++++---- app/Transformer/Api/FilterTransformer.php | 20 ++++++++ app/Transformer/Api/HashtagTransformer.php | 14 +++--- app/Transformer/Api/MediaTransformer.php | 28 +++++------ app/Transformer/Api/ResultsTransformer.php | 24 ++++++++++ 9 files changed, 148 insertions(+), 60 deletions(-) create mode 100644 app/Transformer/Api/AttachmentTransformer.php create mode 100644 app/Transformer/Api/ContextTransformer.php create mode 100644 app/Transformer/Api/FilterTransformer.php create mode 100644 app/Transformer/Api/ResultsTransformer.php diff --git a/app/Transformer/Api/AccountTransformer.php b/app/Transformer/Api/AccountTransformer.php index 45ff0256..352894e7 100644 --- a/app/Transformer/Api/AccountTransformer.php +++ b/app/Transformer/Api/AccountTransformer.php @@ -7,27 +7,27 @@ use League\Fractal; class AccountTransformer extends Fractal\TransformerAbstract { - public function transform(Profile $profile) - { - return [ - 'id' => $profile->id, - 'username' => $profile->username, - 'acct' => $profile->username, - 'display_name' => $profile->name, - 'locked' => (bool) $profile->is_private, - 'created_at' => $profile->created_at->format('c'), - 'followers_count' => $profile->followerCount(), - 'following_count' => $profile->followingCount(), - 'statuses_count' => $profile->statusCount(), - 'note' => $profile->bio, - 'url' => $profile->url(), - 'avatar' => $profile->avatarUrl(), - 'avatar_static' => $profile->avatarUrl(), - 'header' => null, - 'header_static' => null, - 'moved' => null, - 'fields' => null, - 'bot' => null, - ]; - } + public function transform(Profile $profile) + { + return [ + 'id' => $profile->id, + 'username' => $profile->username, + 'acct' => $profile->username, + 'display_name' => $profile->name, + 'locked' => (bool) $profile->is_private, + 'created_at' => $profile->created_at->format('c'), + 'followers_count' => $profile->followerCount(), + 'following_count' => $profile->followingCount(), + 'statuses_count' => $profile->statusCount(), + 'note' => $profile->bio, + 'url' => $profile->url(), + 'avatar' => $profile->avatarUrl(), + 'avatar_static' => $profile->avatarUrl(), + 'header' => null, + 'header_static' => null, + 'moved' => null, + 'fields' => null, + 'bot' => null, + ]; + } } diff --git a/app/Transformer/Api/ApplicationTransformer.php b/app/Transformer/Api/ApplicationTransformer.php index 23e29afd..158fe9ae 100644 --- a/app/Transformer/Api/ApplicationTransformer.php +++ b/app/Transformer/Api/ApplicationTransformer.php @@ -6,11 +6,11 @@ use League\Fractal; class ApplicationTransformer extends Fractal\TransformerAbstract { - public function transform() - { - return [ - 'name' => '', - 'website' => null, - ]; - } + public function transform() + { + return [ + 'name' => '', + 'website' => null, + ]; + } } diff --git a/app/Transformer/Api/AttachmentTransformer.php b/app/Transformer/Api/AttachmentTransformer.php new file mode 100644 index 00000000..2e1be844 --- /dev/null +++ b/app/Transformer/Api/AttachmentTransformer.php @@ -0,0 +1,28 @@ + $media->id, + 'type' => $media->activityVerb(), + 'url' => $media->url(), + 'remote_url' => null, + 'preview_url' => $media->thumbnailUrl(), + 'text_url' => null, + 'meta' => null, + 'description' => $media->caption, + 'license' => $media->license, + 'is_nsfw' => $media->is_nsfw, + 'orientation' => $media->orientation, + 'filter_name' => $media->filter_name, + 'filter_class' => $media->filter_class, + 'mime' => $media->mime, + ]; + } +} diff --git a/app/Transformer/Api/ContextTransformer.php b/app/Transformer/Api/ContextTransformer.php new file mode 100644 index 00000000..0a6c7822 --- /dev/null +++ b/app/Transformer/Api/ContextTransformer.php @@ -0,0 +1,16 @@ + [], + 'descendants' => [] + ]; + } +} diff --git a/app/Transformer/Api/EmojiTransformer.php b/app/Transformer/Api/EmojiTransformer.php index 0d7fd10f..93c7437c 100644 --- a/app/Transformer/Api/EmojiTransformer.php +++ b/app/Transformer/Api/EmojiTransformer.php @@ -6,13 +6,13 @@ use League\Fractal; class EmojiTransformer extends Fractal\TransformerAbstract { - public function transform($emoji) - { - return [ - 'shortcode' => '', - 'static_url' => '', - 'url' => '', - 'visible_in_picker' => false - ]; - } + public function transform($emoji) + { + return [ + 'shortcode' => '', + 'static_url' => '', + 'url' => '', + 'visible_in_picker' => false + ]; + } } diff --git a/app/Transformer/Api/FilterTransformer.php b/app/Transformer/Api/FilterTransformer.php new file mode 100644 index 00000000..92a6d7d7 --- /dev/null +++ b/app/Transformer/Api/FilterTransformer.php @@ -0,0 +1,20 @@ + (string) '', + 'phrase' => (string) '', + 'context' => [], + 'expires_at' => null, + 'irreversible' => (bool) false, + 'whole_word' => (bool) false + ]; + } +} diff --git a/app/Transformer/Api/HashtagTransformer.php b/app/Transformer/Api/HashtagTransformer.php index 153c311c..b11c0e3b 100644 --- a/app/Transformer/Api/HashtagTransformer.php +++ b/app/Transformer/Api/HashtagTransformer.php @@ -7,11 +7,11 @@ use League\Fractal; class HashtagTransformer extends Fractal\TransformerAbstract { - public function transform(Hashtag $hashtag) - { - return [ - 'name' => $hashtag->name, - 'url' => $hashtag->url(), - ]; - } + public function transform(Hashtag $hashtag) + { + return [ + 'name' => $hashtag->name, + 'url' => $hashtag->url(), + ]; + } } diff --git a/app/Transformer/Api/MediaTransformer.php b/app/Transformer/Api/MediaTransformer.php index 8ab38fc6..2920bea1 100644 --- a/app/Transformer/Api/MediaTransformer.php +++ b/app/Transformer/Api/MediaTransformer.php @@ -10,20 +10,20 @@ class MediaTransformer extends Fractal\TransformerAbstract public function transform(Media $media) { return [ - 'id' => $media->id, - 'type' => $media->activityVerb(), - 'url' => $media->url(), - 'remote_url' => null, - 'preview_url' => $media->thumbnailUrl(), - 'text_url' => null, - 'meta' => null, - 'description' => $media->caption, - 'license' => $media->license, - 'is_nsfw' => $media->is_nsfw, - 'orientation' => $media->orientation, - 'filter_name' => $media->filter_name, - 'filter_class' => $media->filter_class, - 'mime' => $media->mime, + 'id' => $media->id, + 'type' => $media->activityVerb(), + 'url' => $media->url(), + 'remote_url' => null, + 'preview_url' => $media->thumbnailUrl(), + 'text_url' => null, + 'meta' => null, + 'description' => $media->caption, + 'license' => $media->license, + 'is_nsfw' => $media->is_nsfw, + 'orientation' => $media->orientation, + 'filter_name' => $media->filter_name, + 'filter_class' => $media->filter_class, + 'mime' => $media->mime, ]; } } diff --git a/app/Transformer/Api/ResultsTransformer.php b/app/Transformer/Api/ResultsTransformer.php new file mode 100644 index 00000000..ea247360 --- /dev/null +++ b/app/Transformer/Api/ResultsTransformer.php @@ -0,0 +1,24 @@ + [], + 'statuses' => [], + 'hashtags' => [] + ]; + } +} From ac27365a637facb34ce4506baa514892e423075a Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 30 Dec 2018 21:30:57 -0700 Subject: [PATCH 011/108] Add laravel passport --- app/Providers/AuthServiceProvider.php | 7 ++++++- config/auth.php | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/Providers/AuthServiceProvider.php b/app/Providers/AuthServiceProvider.php index 9e68caa6..dbbbece8 100644 --- a/app/Providers/AuthServiceProvider.php +++ b/app/Providers/AuthServiceProvider.php @@ -3,6 +3,7 @@ namespace App\Providers; use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; +use Laravel\Passport\Passport; class AuthServiceProvider extends ServiceProvider { @@ -24,6 +25,10 @@ class AuthServiceProvider extends ServiceProvider { $this->registerPolicies(); - // + Passport::routes(); + + Passport::tokensExpireIn(now()->addDays(15)); + + Passport::refreshTokensExpireIn(now()->addDays(30)); } } diff --git a/config/auth.php b/config/auth.php index a9264b4a..3b50d4c1 100644 --- a/config/auth.php +++ b/config/auth.php @@ -42,7 +42,7 @@ return [ ], 'api' => [ - 'driver' => 'token', + 'driver' => 'passport', 'provider' => 'users', ], ], From 067a2db5d0261f1cf4fd014aa6312dc88e08c563 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 30 Dec 2018 21:31:57 -0700 Subject: [PATCH 012/108] Add scoped css to vue components --- resources/assets/js/components/PostComments.vue | 2 +- resources/assets/js/components/PostComponent.vue | 2 +- resources/assets/js/components/Timeline.vue | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/resources/assets/js/components/PostComments.vue b/resources/assets/js/components/PostComments.vue index fc9990c1..152feb3c 100644 --- a/resources/assets/js/components/PostComments.vue +++ b/resources/assets/js/components/PostComments.vue @@ -1,4 +1,4 @@ - + + \ No newline at end of file From ba8c1017035b7edc8d6d9aea10dbb294e1c36f94 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 12 Jan 2019 13:46:14 -0700 Subject: [PATCH 076/108] Update FollowerController --- app/Http/Controllers/FollowerController.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/FollowerController.php b/app/Http/Controllers/FollowerController.php index e312a293..d0ebb5fc 100644 --- a/app/Http/Controllers/FollowerController.php +++ b/app/Http/Controllers/FollowerController.php @@ -39,6 +39,7 @@ class FollowerController extends Controller $user = Auth::user()->profile; $target = Profile::where('id', '!=', $user->id)->whereNull('status')->findOrFail($item); $private = (bool) $target->is_private; + $remote = (bool) $target->domain; $blocked = UserFilter::whereUserId($target->id) ->whereFilterType('block') ->whereFilterableId($user->id) @@ -51,7 +52,7 @@ class FollowerController extends Controller $isFollowing = Follower::whereProfileId($user->id)->whereFollowingId($target->id)->count(); - if($private == true && $isFollowing == 0) { + if($private == true && $isFollowing == 0 || $remote == true) { $follow = FollowRequest::firstOrCreate([ 'follower_id' => $user->id, 'following_id' => $target->id From 84960d701cf873bc7d33e6c937d32bf89b40bd90 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 12 Jan 2019 13:58:35 -0700 Subject: [PATCH 077/108] Add API Search ResultsTransformer --- app/Transformer/Api/ResultsTransformer.php | 28 ++++++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/app/Transformer/Api/ResultsTransformer.php b/app/Transformer/Api/ResultsTransformer.php index ea247360..781e9ddf 100644 --- a/app/Transformer/Api/ResultsTransformer.php +++ b/app/Transformer/Api/ResultsTransformer.php @@ -8,12 +8,12 @@ class ResultsTransformer extends Fractal\TransformerAbstract { protected $defaultIncludes = [ - 'account', - 'mentions', - 'media_attachments', - 'tags', + 'accounts', + 'statuses', + 'hashtags', ]; - public function transform() + + public function transform($results) { return [ 'accounts' => [], @@ -21,4 +21,22 @@ class ResultsTransformer extends Fractal\TransformerAbstract 'hashtags' => [] ]; } + + public function includeAccounts($results) + { + $accounts = $results->accounts; + return $this->collection($accounts, new AccountTransformer()); + } + + public function includeStatuses($results) + { + $statuses = $results->statuses; + return $this->collection($statuses, new StatusTransformer()); + } + + public function includeTags($results) + { + $hashtags = $status->hashtags; + return $this->collection($hashtags, new HashtagTransformer()); + } } From bb2ad95e55a1338224827a48ccd64cf5e0f19aff Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 12 Jan 2019 15:16:37 -0700 Subject: [PATCH 078/108] Update LikePipeline --- app/Jobs/LikePipeline/LikePipeline.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/Jobs/LikePipeline/LikePipeline.php b/app/Jobs/LikePipeline/LikePipeline.php index f1c04b62..e1404783 100644 --- a/app/Jobs/LikePipeline/LikePipeline.php +++ b/app/Jobs/LikePipeline/LikePipeline.php @@ -19,6 +19,13 @@ class LikePipeline implements ShouldQueue protected $like; + /** + * Delete the job if its models no longer exist. + * + * @var bool + */ + public $deleteWhenMissingModels = true; + /** * Create a new job instance. * From 7e16e9d43f52f1ebef18f659bf5bcb7321ca4923 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 12 Jan 2019 15:17:28 -0700 Subject: [PATCH 079/108] Update MentionPipeline --- app/Jobs/MentionPipeline/MentionPipeline.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/Jobs/MentionPipeline/MentionPipeline.php b/app/Jobs/MentionPipeline/MentionPipeline.php index 8029e231..e75ede04 100644 --- a/app/Jobs/MentionPipeline/MentionPipeline.php +++ b/app/Jobs/MentionPipeline/MentionPipeline.php @@ -18,6 +18,13 @@ class MentionPipeline implements ShouldQueue protected $status; protected $mention; + /** + * Delete the job if its models no longer exist. + * + * @var bool + */ + public $deleteWhenMissingModels = true; + /** * Create a new job instance. * From 219362b415bb28621a18f37b894555c61df8d3f9 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 12 Jan 2019 15:18:33 -0700 Subject: [PATCH 080/108] Update SharePipeline --- app/Jobs/SharePipeline/SharePipeline.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/app/Jobs/SharePipeline/SharePipeline.php b/app/Jobs/SharePipeline/SharePipeline.php index 8d72376c..4e2fbce5 100644 --- a/app/Jobs/SharePipeline/SharePipeline.php +++ b/app/Jobs/SharePipeline/SharePipeline.php @@ -19,6 +19,13 @@ class SharePipeline implements ShouldQueue protected $like; + /** + * Delete the job if its models no longer exist. + * + * @var bool + */ + public $deleteWhenMissingModels = true; + /** * Create a new job instance. * @@ -45,10 +52,10 @@ class SharePipeline implements ShouldQueue return; } - $exists = Notification::whereProfileId($status->profile_id) - ->whereActorId($actor->id) - ->whereAction('like') - ->whereItemId($status->id) + $exists = Notification::whereProfileId($target->id) + ->whereActorId($status->profile_id) + ->whereAction('share') + ->whereItemId($status->in_reply_to_id) ->whereItemType('App\Status') ->count(); @@ -57,10 +64,12 @@ class SharePipeline implements ShouldQueue } try { + $text = "{$actor->username} " . __('notification.likedPhoto'); + $html = ''; $notification = new Notification(); $notification->profile_id = $status->profile_id; $notification->actor_id = $actor->id; - $notification->action = 'like'; + $notification->action = 'share'; $notification->message = $like->toText(); $notification->rendered = $like->toHtml(); $notification->item_id = $status->id; From 8edeab11d6053ee01c4c377a126da30162343898 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 12 Jan 2019 15:19:57 -0700 Subject: [PATCH 081/108] Update StatusPipeline --- app/Jobs/StatusPipeline/NewStatusPipeline.php | 9 ++++++++- app/Jobs/StatusPipeline/StatusActivityPubDeliver.php | 9 ++++++++- app/Jobs/StatusPipeline/StatusDelete.php | 9 ++++++++- app/Jobs/StatusPipeline/StatusEntityLexer.php | 9 ++++++++- 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/app/Jobs/StatusPipeline/NewStatusPipeline.php b/app/Jobs/StatusPipeline/NewStatusPipeline.php index efb7d6b1..2ba51114 100644 --- a/app/Jobs/StatusPipeline/NewStatusPipeline.php +++ b/app/Jobs/StatusPipeline/NewStatusPipeline.php @@ -16,7 +16,14 @@ class NewStatusPipeline implements ShouldQueue use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; protected $status; - + + /** + * Delete the job if its models no longer exist. + * + * @var bool + */ + public $deleteWhenMissingModels = true; + /** * Create a new job instance. * diff --git a/app/Jobs/StatusPipeline/StatusActivityPubDeliver.php b/app/Jobs/StatusPipeline/StatusActivityPubDeliver.php index 12a66c37..304ee8cc 100644 --- a/app/Jobs/StatusPipeline/StatusActivityPubDeliver.php +++ b/app/Jobs/StatusPipeline/StatusActivityPubDeliver.php @@ -18,7 +18,14 @@ class StatusActivityPubDeliver implements ShouldQueue use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; protected $status; - + + /** + * Delete the job if its models no longer exist. + * + * @var bool + */ + public $deleteWhenMissingModels = true; + /** * Create a new job instance. * diff --git a/app/Jobs/StatusPipeline/StatusDelete.php b/app/Jobs/StatusPipeline/StatusDelete.php index 9cf6fe03..d852c112 100644 --- a/app/Jobs/StatusPipeline/StatusDelete.php +++ b/app/Jobs/StatusPipeline/StatusDelete.php @@ -19,7 +19,14 @@ class StatusDelete implements ShouldQueue use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; protected $status; - + + /** + * Delete the job if its models no longer exist. + * + * @var bool + */ + public $deleteWhenMissingModels = true; + /** * Create a new job instance. * diff --git a/app/Jobs/StatusPipeline/StatusEntityLexer.php b/app/Jobs/StatusPipeline/StatusEntityLexer.php index cb390f8e..72cd0394 100644 --- a/app/Jobs/StatusPipeline/StatusEntityLexer.php +++ b/app/Jobs/StatusPipeline/StatusEntityLexer.php @@ -24,7 +24,14 @@ class StatusEntityLexer implements ShouldQueue protected $status; protected $entities; protected $autolink; - + + /** + * Delete the job if its models no longer exist. + * + * @var bool + */ + public $deleteWhenMissingModels = true; + /** * Create a new job instance. * From a9e4589e367db44c04df7bcc821ee56416609659 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 12 Jan 2019 15:20:54 -0700 Subject: [PATCH 082/108] Update InstagramImportPipeline --- app/Jobs/ImportPipeline/ImportInstagram.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/Jobs/ImportPipeline/ImportInstagram.php b/app/Jobs/ImportPipeline/ImportInstagram.php index d374fcc9..57b1b5fc 100644 --- a/app/Jobs/ImportPipeline/ImportInstagram.php +++ b/app/Jobs/ImportPipeline/ImportInstagram.php @@ -25,7 +25,14 @@ class ImportInstagram implements ShouldQueue use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; protected $job; - + + /** + * Delete the job if its models no longer exist. + * + * @var bool + */ + public $deleteWhenMissingModels = true; + /** * Create a new job instance. * From 49d825f5b2c4daeaeb6ce37b0742d131c61b825e Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 12 Jan 2019 15:21:48 -0700 Subject: [PATCH 083/108] Update ImageOptimizePipeline --- app/Jobs/ImageOptimizePipeline/ImageOptimize.php | 7 +++++++ app/Jobs/ImageOptimizePipeline/ImageResize.php | 7 +++++++ app/Jobs/ImageOptimizePipeline/ImageThumbnail.php | 7 +++++++ app/Jobs/ImageOptimizePipeline/ImageUpdate.php | 7 +++++++ 4 files changed, 28 insertions(+) diff --git a/app/Jobs/ImageOptimizePipeline/ImageOptimize.php b/app/Jobs/ImageOptimizePipeline/ImageOptimize.php index 2fdd439c..0a4712bf 100644 --- a/app/Jobs/ImageOptimizePipeline/ImageOptimize.php +++ b/app/Jobs/ImageOptimizePipeline/ImageOptimize.php @@ -15,6 +15,13 @@ class ImageOptimize implements ShouldQueue protected $media; + /** + * Delete the job if its models no longer exist. + * + * @var bool + */ + public $deleteWhenMissingModels = true; + /** * Create a new job instance. * diff --git a/app/Jobs/ImageOptimizePipeline/ImageResize.php b/app/Jobs/ImageOptimizePipeline/ImageResize.php index f7dd622b..9d8a3c31 100644 --- a/app/Jobs/ImageOptimizePipeline/ImageResize.php +++ b/app/Jobs/ImageOptimizePipeline/ImageResize.php @@ -16,6 +16,13 @@ class ImageResize implements ShouldQueue protected $media; + /** + * Delete the job if its models no longer exist. + * + * @var bool + */ + public $deleteWhenMissingModels = true; + /** * Create a new job instance. * diff --git a/app/Jobs/ImageOptimizePipeline/ImageThumbnail.php b/app/Jobs/ImageOptimizePipeline/ImageThumbnail.php index 601c010b..93f35a3d 100644 --- a/app/Jobs/ImageOptimizePipeline/ImageThumbnail.php +++ b/app/Jobs/ImageOptimizePipeline/ImageThumbnail.php @@ -17,6 +17,13 @@ class ImageThumbnail implements ShouldQueue protected $media; + /** + * Delete the job if its models no longer exist. + * + * @var bool + */ + public $deleteWhenMissingModels = true; + /** * Create a new job instance. * diff --git a/app/Jobs/ImageOptimizePipeline/ImageUpdate.php b/app/Jobs/ImageOptimizePipeline/ImageUpdate.php index 173dd9f3..37a51cb8 100644 --- a/app/Jobs/ImageOptimizePipeline/ImageUpdate.php +++ b/app/Jobs/ImageOptimizePipeline/ImageUpdate.php @@ -23,6 +23,13 @@ class ImageUpdate implements ShouldQueue 'image/png', ]; + /** + * Delete the job if its models no longer exist. + * + * @var bool + */ + public $deleteWhenMissingModels = true; + /** * Create a new job instance. * From 52bbe0061a48e7dd481d32faa3dd132e93da711a Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 12 Jan 2019 15:22:34 -0700 Subject: [PATCH 084/108] Update FollowPipeline --- app/Jobs/FollowPipeline/FollowActivityPubDeliver.php | 7 +++++++ app/Jobs/FollowPipeline/FollowPipeline.php | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/app/Jobs/FollowPipeline/FollowActivityPubDeliver.php b/app/Jobs/FollowPipeline/FollowActivityPubDeliver.php index 863b2881..56f22d99 100644 --- a/app/Jobs/FollowPipeline/FollowActivityPubDeliver.php +++ b/app/Jobs/FollowPipeline/FollowActivityPubDeliver.php @@ -21,6 +21,13 @@ class FollowActivityPubDeliver implements ShouldQueue protected $followRequest; + /** + * Delete the job if its models no longer exist. + * + * @var bool + */ + public $deleteWhenMissingModels = true; + /** * Create a new job instance. * diff --git a/app/Jobs/FollowPipeline/FollowPipeline.php b/app/Jobs/FollowPipeline/FollowPipeline.php index 8e3bc2ed..ec6c7ecb 100644 --- a/app/Jobs/FollowPipeline/FollowPipeline.php +++ b/app/Jobs/FollowPipeline/FollowPipeline.php @@ -18,6 +18,13 @@ class FollowPipeline implements ShouldQueue protected $follower; + /** + * Delete the job if its models no longer exist. + * + * @var bool + */ + public $deleteWhenMissingModels = true; + /** * Create a new job instance. * From 8c0119e69df8c9e253eb7783ce8e9da4fd81672a Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 12 Jan 2019 15:23:22 -0700 Subject: [PATCH 085/108] Update CommentPipeline --- app/Jobs/CommentPipeline/CommentPipeline.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/Jobs/CommentPipeline/CommentPipeline.php b/app/Jobs/CommentPipeline/CommentPipeline.php index 8c1eb21a..bafe9baf 100644 --- a/app/Jobs/CommentPipeline/CommentPipeline.php +++ b/app/Jobs/CommentPipeline/CommentPipeline.php @@ -20,6 +20,13 @@ class CommentPipeline implements ShouldQueue protected $status; protected $comment; + /** + * Delete the job if its models no longer exist. + * + * @var bool + */ + public $deleteWhenMissingModels = true; + /** * Create a new job instance. * From 7316ee38c413fdb81d120096697526ca4194aaef Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 12 Jan 2019 15:24:20 -0700 Subject: [PATCH 086/108] Update AvatarPipeline --- app/Jobs/AvatarPipeline/AvatarOptimize.php | 7 +++++++ app/Jobs/AvatarPipeline/CreateAvatar.php | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/app/Jobs/AvatarPipeline/AvatarOptimize.php b/app/Jobs/AvatarPipeline/AvatarOptimize.php index 6a9df55e..346afb01 100644 --- a/app/Jobs/AvatarPipeline/AvatarOptimize.php +++ b/app/Jobs/AvatarPipeline/AvatarOptimize.php @@ -19,6 +19,13 @@ class AvatarOptimize implements ShouldQueue protected $profile; protected $current; + /** + * Delete the job if its models no longer exist. + * + * @var bool + */ + public $deleteWhenMissingModels = true; + /** * Create a new job instance. * diff --git a/app/Jobs/AvatarPipeline/CreateAvatar.php b/app/Jobs/AvatarPipeline/CreateAvatar.php index 06c42af8..2b50ccba 100644 --- a/app/Jobs/AvatarPipeline/CreateAvatar.php +++ b/app/Jobs/AvatarPipeline/CreateAvatar.php @@ -20,6 +20,13 @@ class CreateAvatar implements ShouldQueue protected $profile; + /** + * Delete the job if its models no longer exist. + * + * @var bool + */ + public $deleteWhenMissingModels = true; + /** * Create a new job instance. * From b4221833e3fde6dc17365bf761b06fc60553f050 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 13 Jan 2019 00:10:07 -0700 Subject: [PATCH 087/108] Update FederationController, add captcha to nodeinfo. Fixes https://todon.nl/users/v0idifier/statuses/101407970516293946 --- app/Http/Controllers/FederationController.php | 63 ++++++++++--------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/app/Http/Controllers/FederationController.php b/app/Http/Controllers/FederationController.php index 59cd86eb..cc21e962 100644 --- a/app/Http/Controllers/FederationController.php +++ b/app/Http/Controllers/FederationController.php @@ -82,37 +82,38 @@ class FederationController extends Controller { $res = Cache::remember('api:nodeinfo', 60, function () { return [ - 'metadata' => [ - 'nodeName' => config('app.name'), - 'software' => [ - 'homepage' => 'https://pixelfed.org', - 'github' => 'https://github.com/pixelfed', - 'follow' => 'https://mastodon.social/@pixelfed', - ], - ], - 'openRegistrations' => config('pixelfed.open_registration'), - 'protocols' => [ - 'activitypub', - ], - 'services' => [ - 'inbound' => [], - 'outbound' => [], - ], - 'software' => [ - 'name' => 'pixelfed', - 'version' => config('pixelfed.version'), - ], - 'usage' => [ - 'localPosts' => \App\Status::whereLocal(true)->whereHas('media')->count(), - 'localComments' => \App\Status::whereLocal(true)->whereNotNull('in_reply_to_id')->count(), - 'users' => [ - 'total' => \App\User::count(), - 'activeHalfyear' => \App\AccountLog::select('user_id')->whereAction('auth.login')->where('updated_at', '>',Carbon::now()->subMonths(6)->toDateTimeString())->groupBy('user_id')->get()->count(), - 'activeMonth' => \App\AccountLog::select('user_id')->whereAction('auth.login')->where('updated_at', '>',Carbon::now()->subMonths(1)->toDateTimeString())->groupBy('user_id')->get()->count(), - ], - ], - 'version' => '2.0', - ]; + 'metadata' => [ + 'nodeName' => config('app.name'), + 'software' => [ + 'homepage' => 'https://pixelfed.org', + 'github' => 'https://github.com/pixelfed', + 'follow' => 'https://mastodon.social/@pixelfed', + ], + 'captcha' => (bool) config('pixelfed.recaptcha'), + ], + 'openRegistrations' => config('pixelfed.open_registration'), + 'protocols' => [ + 'activitypub', + ], + 'services' => [ + 'inbound' => [], + 'outbound' => [], + ], + 'software' => [ + 'name' => 'pixelfed', + 'version' => config('pixelfed.version'), + ], + 'usage' => [ + 'localPosts' => \App\Status::whereLocal(true)->whereHas('media')->count(), + 'localComments' => \App\Status::whereLocal(true)->whereNotNull('in_reply_to_id')->count(), + 'users' => [ + 'total' => \App\User::count(), + 'activeHalfyear' => \App\AccountLog::select('user_id')->whereAction('auth.login')->where('updated_at', '>',Carbon::now()->subMonths(6)->toDateTimeString())->groupBy('user_id')->get()->count(), + 'activeMonth' => \App\AccountLog::select('user_id')->whereAction('auth.login')->where('updated_at', '>',Carbon::now()->subMonths(1)->toDateTimeString())->groupBy('user_id')->get()->count(), + ], + ], + 'version' => '2.0', + ]; }); return response()->json($res, 200, [ From aa53a1439fa8f69258552c68a933310f2dabf22a Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 13 Jan 2019 15:55:26 -0700 Subject: [PATCH 088/108] Update API AccountTransformer, fix https://mastodon.social/users/tom79/statuses/101410506495350462 --- app/Transformer/Api/AccountTransformer.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Transformer/Api/AccountTransformer.php b/app/Transformer/Api/AccountTransformer.php index 352894e7..3b82a51b 100644 --- a/app/Transformer/Api/AccountTransformer.php +++ b/app/Transformer/Api/AccountTransformer.php @@ -28,6 +28,7 @@ class AccountTransformer extends Fractal\TransformerAbstract 'moved' => null, 'fields' => null, 'bot' => null, + 'software' => 'pixelfed' ]; } } From e61c6a06e0ee1903b280305172c79d68cab418df Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 13 Jan 2019 22:27:42 -0700 Subject: [PATCH 089/108] Update AuthServiceProvider, add oauth support --- app/Providers/AuthServiceProvider.php | 8 +++----- config/auth.php | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/app/Providers/AuthServiceProvider.php b/app/Providers/AuthServiceProvider.php index cceede8c..585cd092 100644 --- a/app/Providers/AuthServiceProvider.php +++ b/app/Providers/AuthServiceProvider.php @@ -25,10 +25,8 @@ class AuthServiceProvider extends ServiceProvider { $this->registerPolicies(); - // Passport::routes(); - - // Passport::tokensExpireIn(now()->addDays(15)); - - // Passport::refreshTokensExpireIn(now()->addDays(30)); + Passport::routes(); + Passport::tokensExpireIn(now()->addDays(15)); + Passport::refreshTokensExpireIn(now()->addDays(30)); } } diff --git a/config/auth.php b/config/auth.php index a9264b4a..3b50d4c1 100644 --- a/config/auth.php +++ b/config/auth.php @@ -42,7 +42,7 @@ return [ ], 'api' => [ - 'driver' => 'token', + 'driver' => 'passport', 'provider' => 'users', ], ], From 30758e5e6796050605cb1963c2d37d150d9ddfe2 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Mon, 14 Jan 2019 22:34:27 -0700 Subject: [PATCH 090/108] Update NotificationTransformer --- app/Transformer/Api/NotificationTransformer.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Transformer/Api/NotificationTransformer.php b/app/Transformer/Api/NotificationTransformer.php index 16d537c9..991848e3 100644 --- a/app/Transformer/Api/NotificationTransformer.php +++ b/app/Transformer/Api/NotificationTransformer.php @@ -44,6 +44,7 @@ class NotificationTransformer extends Fractal\TransformerAbstract 'follow' => 'follow', 'mention' => 'mention', 'reblog' => 'share', + 'share' => 'share', 'like' => 'favourite', 'comment' => 'comment', ]; From 9765ec3d68e79b3eccf41905f745be74825757a6 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Mon, 14 Jan 2019 22:34:50 -0700 Subject: [PATCH 091/108] Update Status Model --- app/Status.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/app/Status.php b/app/Status.php index 6bb36347..466ed410 100644 --- a/app/Status.php +++ b/app/Status.php @@ -274,6 +274,22 @@ class Status extends Model __('notification.commented'); } + public function shareToText() + { + $actorName = $this->profile->username; + + return "{$actorName} ".__('notification.shared'); + } + + public function shareToHtml() + { + $actorName = $this->profile->username; + $actorUrl = $this->profile->url(); + + return "{$actorName} ". + __('notification.shared'); + } + public function recentComments() { return $this->comments()->orderBy('created_at', 'desc')->take(3); From 63d7e4ecaaad0e8be6f4aa06f97110df77c90a25 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Mon, 14 Jan 2019 22:43:53 -0700 Subject: [PATCH 092/108] Update SharePipeline --- app/Jobs/SharePipeline/SharePipeline.php | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/app/Jobs/SharePipeline/SharePipeline.php b/app/Jobs/SharePipeline/SharePipeline.php index 4e2fbce5..6d581eb7 100644 --- a/app/Jobs/SharePipeline/SharePipeline.php +++ b/app/Jobs/SharePipeline/SharePipeline.php @@ -17,7 +17,7 @@ class SharePipeline implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; - protected $like; + protected $status; /** * Delete the job if its models no longer exist. @@ -44,10 +44,10 @@ class SharePipeline implements ShouldQueue public function handle() { $status = $this->status; - $actor = $this->status->profile; - $target = $this->status->parent()->profile; + $actor = $status->profile; + $target = $status->parent()->profile; - if ($status->url !== null) { + if ($status->uri !== null) { // Ignore notifications to remote statuses return; } @@ -55,23 +55,21 @@ class SharePipeline implements ShouldQueue $exists = Notification::whereProfileId($target->id) ->whereActorId($status->profile_id) ->whereAction('share') - ->whereItemId($status->in_reply_to_id) + ->whereItemId($status->reblog_of_id) ->whereItemType('App\Status') ->count(); - if ($actor->id === $status->profile_id || $exists !== 0) { + if ($target->id === $status->profile_id || $exists !== 0) { return true; } try { - $text = "{$actor->username} " . __('notification.likedPhoto'); - $html = ''; - $notification = new Notification(); - $notification->profile_id = $status->profile_id; + $notification = new Notification; + $notification->profile_id = $target->id; $notification->actor_id = $actor->id; $notification->action = 'share'; - $notification->message = $like->toText(); - $notification->rendered = $like->toHtml(); + $notification->message = $status->shareToText(); + $notification->rendered = $status->shareToHtml(); $notification->item_id = $status->id; $notification->item_type = "App\Status"; $notification->save(); From 7d9c7bf59e6f8d9aa361791c52d45b7d5d37a1b5 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Mon, 14 Jan 2019 22:44:23 -0700 Subject: [PATCH 093/108] Update StatusController --- app/Http/Controllers/StatusController.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/Http/Controllers/StatusController.php b/app/Http/Controllers/StatusController.php index 1de2ad66..7c0d3472 100644 --- a/app/Http/Controllers/StatusController.php +++ b/app/Http/Controllers/StatusController.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers; use App\Jobs\ImageOptimizePipeline\ImageOptimize; use App\Jobs\StatusPipeline\NewStatusPipeline; use App\Jobs\StatusPipeline\StatusDelete; +use App\Jobs\SharePipeline\SharePipeline; use App\Media; use App\Profile; use App\Status; @@ -234,8 +235,10 @@ class StatusController extends Controller $share = new Status(); $share->profile_id = $profile->id; $share->reblog_of_id = $status->id; + $share->in_reply_to_profile_id = $status->profile_id; $share->save(); $count++; + SharePipeline::dispatch($share); } if ($request->ajax()) { From a0634b4476f03f0652214cf6f48cb596e4fc4f94 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Wed, 16 Jan 2019 21:45:50 -0700 Subject: [PATCH 094/108] Add missing svgs --- public/svg/403.svg | 1 + public/svg/404.svg | 1 + public/svg/500.svg | 1 + public/svg/503.svg | 1 + 4 files changed, 4 insertions(+) create mode 100755 public/svg/403.svg create mode 100755 public/svg/404.svg create mode 100755 public/svg/500.svg create mode 100755 public/svg/503.svg diff --git a/public/svg/403.svg b/public/svg/403.svg new file mode 100755 index 00000000..682aa982 --- /dev/null +++ b/public/svg/403.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/public/svg/404.svg b/public/svg/404.svg new file mode 100755 index 00000000..b6cd6f23 --- /dev/null +++ b/public/svg/404.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/public/svg/500.svg b/public/svg/500.svg new file mode 100755 index 00000000..9927e8d7 --- /dev/null +++ b/public/svg/500.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/public/svg/503.svg b/public/svg/503.svg new file mode 100755 index 00000000..6ad10933 --- /dev/null +++ b/public/svg/503.svg @@ -0,0 +1 @@ + \ No newline at end of file From 530b234f4044a07c92136df6a469e63fe63c27ef Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Thu, 17 Jan 2019 13:27:14 -0700 Subject: [PATCH 095/108] Update ProfileController, fixes #788 --- app/Http/Controllers/ProfileController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php index 070fc308..0e9271ab 100644 --- a/app/Http/Controllers/ProfileController.php +++ b/app/Http/Controllers/ProfileController.php @@ -187,7 +187,7 @@ class ProfileController extends Controller return view('profile.private', compact('user', 'is_following')); } } - $followers = $profile->followers()->whereNull('status')->orderBy('created_at', 'desc')->simplePaginate(12); + $followers = $profile->followers()->whereNull('status')->orderBy('followers.created_at', 'desc')->simplePaginate(12); $is_admin = is_null($user->domain) ? $user->user->is_admin : false; if ($user->remote_url) { $settings = new \StdClass; @@ -217,7 +217,7 @@ class ProfileController extends Controller return view('profile.private', compact('user', 'is_following')); } } - $following = $profile->following()->whereNull('status')->orderBy('created_at', 'desc')->simplePaginate(12); + $following = $profile->following()->whereNull('status')->orderBy('followers.created_at', 'desc')->simplePaginate(12); $is_admin = is_null($user->domain) ? $user->user->is_admin : false; if ($user->remote_url) { $settings = new \StdClass; From c2635fa1073859600f1dc15fbdded349fc199b9e Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 20 Jan 2019 16:25:12 -0700 Subject: [PATCH 096/108] Update Instance model --- app/Instance.php | 55 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/app/Instance.php b/app/Instance.php index d4c73917..3236819f 100644 --- a/app/Instance.php +++ b/app/Instance.php @@ -6,5 +6,58 @@ use Illuminate\Database\Eloquent\Model; class Instance extends Model { - protected $fillable = ['domain']; + protected $fillable = ['domain']; + + public function profiles() + { + return $this->hasMany(Profile::class, 'domain', 'domain'); + } + + public function statuses() + { + return $this->hasManyThrough( + Status::class, + Profile::class, + 'domain', + 'profile_id', + 'domain', + 'id' + ); + } + + public function reported() + { + return $this->hasManyThrough( + Report::class, + Profile::class, + 'domain', + 'reported_profile_id', + 'domain', + 'id' + ); + } + + public function reports() + { + return $this->hasManyThrough( + Report::class, + Profile::class, + 'domain', + 'profile_id', + 'domain', + 'id' + ); + } + + public function media() + { + return $this->hasManyThrough( + Media::class, + Profile::class, + 'domain', + 'profile_id', + 'domain', + 'id' + ); + } } From dd80bdcd94a4c5ed6c05e764ada66d989571c236 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 20 Jan 2019 16:26:03 -0700 Subject: [PATCH 097/108] Add AdminInstanceController --- .../Admin/AdminInstanceController.php | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 app/Http/Controllers/Admin/AdminInstanceController.php diff --git a/app/Http/Controllers/Admin/AdminInstanceController.php b/app/Http/Controllers/Admin/AdminInstanceController.php new file mode 100644 index 00000000..55600fdf --- /dev/null +++ b/app/Http/Controllers/Admin/AdminInstanceController.php @@ -0,0 +1,35 @@ +paginate(5); + return view('admin.instances.home', compact('instances')); + } + + public function instanceScan(Request $request) + { + DB::transaction(function() { + Profile::whereNotNull('domain') + ->groupBy('domain') + ->chunk(50, function($domains) { + foreach($domains as $domain) { + Instance::firstOrCreate([ + 'domain' => $domain->domain + ]); + } + }); + }); + return redirect()->back(); + } + +} \ No newline at end of file From f5a9d588aef5a43581b7ae3ebb50e60578dc520b Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 20 Jan 2019 16:27:24 -0700 Subject: [PATCH 098/108] Add admin instance view --- .../views/admin/instances/home.blade.php | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 resources/views/admin/instances/home.blade.php diff --git a/resources/views/admin/instances/home.blade.php b/resources/views/admin/instances/home.blade.php new file mode 100644 index 00000000..752051b0 --- /dev/null +++ b/resources/views/admin/instances/home.blade.php @@ -0,0 +1,71 @@ +@extends('admin.partial.template') + +@section('section') +
+

Instances

+
+ +
+@if($instances->count() == 0) +
+

Warning

+

No instances were found.

+
+

Do you want to scan and populate instances from Profiles and Statuses?

+

+

+ @csrf + +
+

+@else +
    + @foreach($instances as $instance) +
  • +
    +
    +

    + {{$instance->domain}} +

    +

    + Overview + Actions +

    +
    +
    +
    +

    {{$instance->profiles()->count()}}

    +

    Profiles

    +
    +
    +

    {{$instance->statuses()->count()}}

    +

    Statuses

    +
    +
    +

    {{$instance->reported()->count()}}

    +

    Reports

    +
    +
    +

    0

    +

    Storage Used

    +
    +
    +
    +
  • + @endforeach +
+
+ {{$instances->links()}} +
+@endif +@endsection + +@push('scripts') + +@endpush \ No newline at end of file From f5d809c14b8a112efb6c222cb2cac6c3068480cc Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 20 Jan 2019 20:53:35 -0700 Subject: [PATCH 099/108] Update Instance model --- app/Instance.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/Instance.php b/app/Instance.php index 3236819f..5541d86c 100644 --- a/app/Instance.php +++ b/app/Instance.php @@ -60,4 +60,9 @@ class Instance extends Model 'id' ); } + + public function getUrl() + { + return url("/i/admin/instances/show/{$this->id}"); + } } From b30c8aade5903d07690cb781d2b89aaef7925a0e Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 20 Jan 2019 21:25:52 -0700 Subject: [PATCH 100/108] Update AdminInstanceController --- .../Admin/AdminInstanceController.php | 68 ++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Admin/AdminInstanceController.php b/app/Http/Controllers/Admin/AdminInstanceController.php index 55600fdf..239d70da 100644 --- a/app/Http/Controllers/Admin/AdminInstanceController.php +++ b/app/Http/Controllers/Admin/AdminInstanceController.php @@ -6,13 +6,37 @@ use DB, Cache; use App\{Instance, Profile}; use Carbon\Carbon; use Illuminate\Http\Request; +use Illuminate\Validation\Rule; trait AdminInstanceController { public function instances(Request $request) { - $instances = Instance::orderByDesc('id')->paginate(5); + $this->validate($request, [ + 'filter' => [ + 'nullable', + 'string', + 'min:1', + 'max:20', + Rule::in(['autocw', 'unlisted', 'banned']) + ], + ]); + if($request->has('filter') && $request->filled('filter')) { + switch ($request->filter) { + case 'autocw': + $instances = Instance::whereAutoCw(true)->orderByDesc('id')->paginate(5); + break; + case 'unlisted': + $instances = Instance::whereUnlisted(true)->orderByDesc('id')->paginate(5); + break; + case 'banned': + $instances = Instance::whereBanned(true)->orderByDesc('id')->paginate(5); + break; + } + } else { + $instances = Instance::orderByDesc('id')->paginate(5); + } return view('admin.instances.home', compact('instances')); } @@ -32,4 +56,46 @@ trait AdminInstanceController return redirect()->back(); } + public function instanceShow(Request $request, $id) + { + $instance = Instance::findOrFail($id); + return view('admin.instances.show', compact('instance')); + } + + public function instanceEdit(Request $request, $id) + { + $this->validate($request, [ + 'action' => [ + 'required', + 'string', + 'min:1', + 'max:20', + Rule::in(['autocw', 'unlist', 'ban']) + ], + ]); + + $instance = Instance::findOrFail($id); + $unlisted = $instance->unlisted; + $autocw = $instance->auto_cw; + $banned = $instance->banned; + + switch ($request->action) { + case 'autocw': + $instance->auto_cw = $autocw == true ? false : true; + $instance->save(); + break; + + case 'unlist': + $instance->unlisted = $unlisted == true ? false : true; + $instance->save(); + break; + + case 'ban': + $instance->banned = $banned == true ? false : true; + $instance->save(); + break; + } + + return response()->json([]); + } } \ No newline at end of file From 9a7245d12e8829aab92f27598f53fa98c1272f69 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 20 Jan 2019 21:26:38 -0700 Subject: [PATCH 101/108] Update filters.scss --- resources/assets/sass/components/filters.scss | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/assets/sass/components/filters.scss b/resources/assets/sass/components/filters.scss index 99d026a4..8714a1ee 100644 --- a/resources/assets/sass/components/filters.scss +++ b/resources/assets/sass/components/filters.scss @@ -1,9 +1,9 @@ /*! Instagram.css v0.1.3 | MIT License | github.com/picturepan2/instagram.css */ -[class*="filter"] { +[class*="filter-"] { position: relative; } -[class*="filter"]::before { +[class*="filter-"]::before { display: block; height: 100%; left: 0; From cd6b66b8e6254a2dc28ffc0cfebfaecf982226ab Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 20 Jan 2019 21:28:15 -0700 Subject: [PATCH 102/108] Update admin instance views --- .../views/admin/instances/home.blade.php | 162 +++++++++++++++++- .../views/admin/instances/show.blade.php | 113 ++++++++++++ 2 files changed, 270 insertions(+), 5 deletions(-) create mode 100644 resources/views/admin/instances/show.blade.php diff --git a/resources/views/admin/instances/home.blade.php b/resources/views/admin/instances/home.blade.php index 752051b0..4faea96b 100644 --- a/resources/views/admin/instances/home.blade.php +++ b/resources/views/admin/instances/home.blade.php @@ -2,11 +2,24 @@ @section('section')
-

Instances

+

Instances

+ + +

-@if($instances->count() == 0) +@if($instances->count() == 0 && request()->has('filter') == false)

Warning

No instances were found.

@@ -22,14 +35,29 @@
    @foreach($instances as $instance)
  • -
    +

    {{$instance->domain}}

    - Overview - Actions + Overview + + @if($instance->unlisted) + + @endif + @if($instance->auto_cw) + + @endif + @if($instance->banned) + + @endif

    @@ -66,6 +94,130 @@ $('.filesize').each(function(k,v) { $(this).text(filesize(v.getAttribute('data-size'))) }); + + $('.btn-action').on('click', function(e) { + let id = this.getAttribute('data-instance-id'); + let instanceDomain = this.getAttribute('data-instance-domain'); + let text = 'Domain: ' + instanceDomain; + let unlisted = this.getAttribute('data-instance-unlisted'); + let autocw = this.getAttribute('data-instance-autocw'); + let banned = this.getAttribute('data-instance-banned'); + swal({ + title: 'Instance Actions', + text: text, + icon: 'warning', + buttons: { + unlist: { + text: unlisted == 0 ? "Unlist" : "Re-list", + className: "bg-warning", + value: "unlisted", + }, + cw: { + text: autocw == 0 ? "CW Media" : "Remove AutoCW", + text: autocw == 0 ? "CW Media" : "Remove AutoCW", + className: "bg-warning", + value: "autocw", + }, + ban: { + text: banned == 0 ? "Ban" : "Unban", + className: "bg-danger", + value: "ban", + }, + }, + }) + .then((value) => { + switch (value) { + case "unlisted": + swal({ + title: "Are you sure?", + text: unlisted == 0 ? + "Are you sure you want to unlist " + instanceDomain + " ?" : + "Are you sure you want to remove the unlisted rule of " + instanceDomain + " ?", + icon: "warning", + buttons: true, + dangerMode: true, + }) + .then((unlist) => { + if (unlist) { + axios.post('/i/admin/instances/edit/' + id, { + action: 'unlist' + }).then((res) => { + swal("Domain action was successful! The page will now refresh.", { + icon: "success", + }); + setTimeout(function() { + window.location.href = window.location.href; + }, 5000); + }).catch((err) => { + swal("Something went wrong!", "Please try again later.", "error"); + }) + } else { + swal("Action Cancelled", "You successfully cancelled this action.", "error"); + } + }); + break; + case "autocw": + swal({ + title: "Are you sure?", + text: autocw == 0 ? + "Are you sure you want to auto CW all media from " + instanceDomain + " ?" : + "Are you sure you want to remove the auto cw rule for " + instanceDomain + " ?", + icon: "warning", + buttons: true, + dangerMode: true, + }) + .then((res) => { + if (res) { + axios.post('/i/admin/instances/edit/' + id, { + action: 'autocw' + }).then((res) => { + swal("Domain action was successful! The page will now refresh.", { + icon: "success", + }); + setTimeout(function() { + window.location.href = window.location.href; + }, 5000); + }).catch((err) => { + swal("Something went wrong!", "Please try again later.", "error"); + }) + } else { + swal("Action Cancelled", "You successfully cancelled this action.", "error"); + } + }); + break; + case "ban": + swal({ + title: "Are you sure?", + text: autocw == 0 ? + "Are you sure you want to ban " + instanceDomain + " ?" : + "Are you sure you want unban " + instanceDomain + " ?", + icon: "warning", + buttons: true, + dangerMode: true, + }) + .then((res) => { + if (res) { + axios.post('/i/admin/instances/edit/' + id, { + action: 'ban' + }).then((res) => { + swal("Domain action was successful! The page will now refresh.", { + icon: "success", + }); + setTimeout(function() { + window.location.href = window.location.href; + }, 5000); + }).catch((err) => { + swal("Something went wrong!", "Please try again later.", "error"); + }) + } else { + swal("Action Cancelled", "You successfully cancelled this action.", "error"); + } + }); + break; + + } + }); + }) }); @endpush \ No newline at end of file diff --git a/resources/views/admin/instances/show.blade.php b/resources/views/admin/instances/show.blade.php new file mode 100644 index 00000000..1bd3becd --- /dev/null +++ b/resources/views/admin/instances/show.blade.php @@ -0,0 +1,113 @@ +@extends('admin.partial.template') + +@section('section') +
    +
    +
    +

    Instance Overview

    +

    domain: {{$instance->domain}}

    +
    +
    + Back +
    +
    +
    +
    +
    +
    +

    unlisted: {{$instance->unlisted ? 'true' : 'false'}}

    +
    +
    +

    CW media: {{$instance->auto_cw ? 'true' : 'false'}}

    +
    +
    +

    banned: {{$instance->banned ? 'true' : 'false'}}

    +
    +
    +
    +
    +
    +
    +
    +

    + {{$instance->profiles->count()}} +

    +

    Profiles

    +
    +
    +
    +
    +

    + {{$instance->reports->count()}} +

    +

    Reports

    +
    +
    +
    +
    +
    +
    +

    + {{$instance->statuses->count()}} +

    +

    Statuses

    +
    +
    +
    +
    +

    + 0 +

    +

    Storage Used

    +
    +
    +
    +
    + +
    +
    +
    +
    + Profiles + + View All + +
    +
      + @foreach($instance->profiles()->latest()->take(5)->get() as $profile) +
    • + {{$profile->emailUrl()}} +
    • + @endforeach +
    +
    +
    +
    +
    +
    + Statuses + + View All + +
    + +
    +
    +
    +@endsection + +@push('scripts') + +@endpush \ No newline at end of file From d34eb425b0ad5e62e9fbd15a7962a1c94fd4caa3 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Mon, 21 Jan 2019 12:18:08 -0700 Subject: [PATCH 103/108] Update Media Model --- app/Media.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/app/Media.php b/app/Media.php index 79e399ea..2b77abe4 100644 --- a/app/Media.php +++ b/app/Media.php @@ -17,6 +17,16 @@ class Media extends Model */ protected $dates = ['deleted_at']; + public function status() + { + return $this->belongsTo(Status::class); + } + + public function profile() + { + return $this->belongsTo(Profile::class); + } + public function url() { if(!empty($this->remote_media) && $this->remote_url) { @@ -37,6 +47,11 @@ class Media extends Model return url($url); } + public function thumb() + { + return $this->thumbnailUrl(); + } + public function mimeType() { return explode('/', $this->mime)[0]; From a040dc05e1b369ac8ce7a1b84cce79d87fe8fbd1 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Mon, 21 Jan 2019 12:22:15 -0700 Subject: [PATCH 104/108] Update admin template --- resources/views/admin/partial/template.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/admin/partial/template.blade.php b/resources/views/admin/partial/template.blade.php index df260f7b..3f93d88e 100644 --- a/resources/views/admin/partial/template.blade.php +++ b/resources/views/admin/partial/template.blade.php @@ -1,7 +1,7 @@ @extends('layouts.app') @section('content') - +@yield('header')
    From 0055af468e09597dbbe8af62e99ed0b64b6d8cb4 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Mon, 21 Jan 2019 12:44:16 -0700 Subject: [PATCH 105/108] Add AdminMediaController --- .../Admin/AdminMediaController.php | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 app/Http/Controllers/Admin/AdminMediaController.php diff --git a/app/Http/Controllers/Admin/AdminMediaController.php b/app/Http/Controllers/Admin/AdminMediaController.php new file mode 100644 index 00000000..73692281 --- /dev/null +++ b/app/Http/Controllers/Admin/AdminMediaController.php @@ -0,0 +1,48 @@ +validate($request, [ + 'layout' => [ + 'nullable', + 'string', + 'min:1', + 'max:4', + Rule::in(['grid','list']) + ], + 'search' => 'nullable|string|min:1|max:20' + ]); + if($request->filled('search')) { + $profiles = Profile::where('username', 'like', '%'.$request->input('search').'%')->pluck('id')->toArray(); + $media = Media::whereHas('status') + ->with('status') + ->orderby('id', 'desc') + ->whereIn('profile_id', $profiles) + ->orWhere('mime', $request->input('search')) + ->paginate(12); + } else { + $media = Media::whereHas('status')->with('status')->orderby('id', 'desc')->paginate(12); + } + return view('admin.media.home', compact('media')); + } + + public function mediaShow(Request $request, $id) + { + $media = Media::findOrFail($id); + return view('admin.media.show', compact('media')); + } +} \ No newline at end of file From 8722f830406565b76df354408105f430cf422894 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Mon, 21 Jan 2019 13:01:36 -0700 Subject: [PATCH 106/108] Update BaseApiController --- .../Controllers/Api/BaseApiController.php | 61 ++++++++++++++++--- 1 file changed, 53 insertions(+), 8 deletions(-) diff --git a/app/Http/Controllers/Api/BaseApiController.php b/app/Http/Controllers/Api/BaseApiController.php index c87dd198..c890f384 100644 --- a/app/Http/Controllers/Api/BaseApiController.php +++ b/app/Http/Controllers/Api/BaseApiController.php @@ -13,7 +13,8 @@ use App\{ Avatar, Notification, Media, - Profile + Profile, + Status }; use App\Transformer\Api\{ AccountTransformer, @@ -23,6 +24,7 @@ use App\Transformer\Api\{ }; use League\Fractal; use League\Fractal\Serializer\ArraySerializer; +use League\Fractal\Pagination\IlluminatePaginatorAdapter; use App\Jobs\AvatarPipeline\AvatarOptimize; use App\Jobs\ImageOptimizePipeline\ImageOptimize; use App\Jobs\VideoPipeline\{ @@ -97,18 +99,52 @@ class BaseApiController extends Controller public function accountStatuses(Request $request, $id) { - $pid = Auth::user()->profile->id; - $profile = Profile::findOrFail($id); - $statuses = $profile->statuses(); - if($pid === $profile->id) { - $statuses = $statuses->orderBy('id', 'desc')->paginate(20); + $this->validate($request, [ + 'only_media' => 'nullable', + 'pinned' => 'nullable', + 'exclude_replies' => 'nullable', + 'max_id' => 'nullable|integer|min:1', + 'since_id' => 'nullable|integer|min:1', + 'min_id' => 'nullable|integer|min:1', + 'limit' => 'nullable|integer|min:1|max:24' + ]); + $limit = $request->limit ?? 20; + $max_id = $request->max_id ?? false; + $min_id = $request->min_id ?? false; + $since_id = $request->since_id ?? false; + $only_media = $request->only_media ?? false; + $user = Auth::user(); + $account = Profile::findOrFail($id); + $statuses = $account->statuses()->getQuery(); + if($only_media == true) { + $statuses = $statuses + ->whereHas('media') + ->whereNull('in_reply_to_id') + ->whereNull('reblog_of_id'); + } + if($id == $account->id && !$max_id && !$min_id && !$since_id) { + $statuses = $statuses->orderBy('id', 'desc') + ->paginate($limit); + } else if($since_id) { + $statuses = $statuses->where('id', '>', $since_id) + ->orderBy('id', 'DESC') + ->paginate($limit); + } else if($min_id) { + $statuses = $statuses->where('id', '>', $min_id) + ->orderBy('id', 'ASC') + ->paginate($limit); + } else if($max_id) { + $statuses = $statuses->where('id', '<', $max_id) + ->orderBy('id', 'DESC') + ->paginate($limit); } else { - $statuses = $statuses->whereVisibility('public')->orderBy('id', 'desc')->paginate(20); + $statuses = $statuses->whereVisibility('public')->orderBy('id', 'desc')->paginate($limit); } $resource = new Fractal\Resource\Collection($statuses, new StatusTransformer()); + //$resource->setPaginator(new IlluminatePaginatorAdapter($statuses)); $res = $this->fractal->createData($resource)->toArray(); - return response()->json($res); + return response()->json($res, 200, [], JSON_PRETTY_PRINT); } public function followSuggestions(Request $request) @@ -265,4 +301,13 @@ class BaseApiController extends Controller return response()->json($res); } + + public function showAccount(Request $request, $id) + { + $profile = Profile::whereNull('domain')->whereNull('status')->findOrFail($id); + $resource = new Fractal\Resource\Item($profile, new AccountTransformer()); + $res = $this->fractal->createData($resource)->toArray(); + + return response()->json($res); + } } From 2fe66b63f06603b51ff7a39c12606ae3f2707519 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Mon, 21 Jan 2019 13:10:30 -0700 Subject: [PATCH 107/108] Add admin media show view --- resources/views/admin/media/show.blade.php | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 resources/views/admin/media/show.blade.php diff --git a/resources/views/admin/media/show.blade.php b/resources/views/admin/media/show.blade.php new file mode 100644 index 00000000..6422a0c0 --- /dev/null +++ b/resources/views/admin/media/show.blade.php @@ -0,0 +1,41 @@ +@extends('admin.partial.template') + +@section('section') +
    +

    Media

    +

    ID: {{$media->id}}

    +
    +
    +
    +
    +
    + + +
    +
    +
    +@endsection + +@push('scripts') + +@endpush \ No newline at end of file From 560ac0f24781829c3b234e0c8a96a284cc0dfc0c Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Mon, 21 Jan 2019 19:59:25 -0700 Subject: [PATCH 108/108] Update RestrictedNames --- app/Util/Lexer/RestrictedNames.php | 54 +++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 16 deletions(-) diff --git a/app/Util/Lexer/RestrictedNames.php b/app/Util/Lexer/RestrictedNames.php index 21f58473..1afe92a5 100644 --- a/app/Util/Lexer/RestrictedNames.php +++ b/app/Util/Lexer/RestrictedNames.php @@ -17,15 +17,6 @@ class RestrictedNames 'contact-us', 'contact_us', 'copyright', - 'd', - 'dashboard', - 'dev', - 'developer', - 'developers', - 'discover', - 'discovers', - 'doc', - 'docs', 'download', 'domainadmin', 'domainadministrator', @@ -41,10 +32,7 @@ class RestrictedNames 'guests', 'hostmaster', 'hostmaster', - 'image', - 'images', 'imap', - 'img', 'info', 'info', 'is', @@ -57,7 +45,6 @@ class RestrictedNames 'mailerdaemon', 'marketing', 'me', - 'media', 'mis', 'mx', 'new', @@ -82,7 +69,6 @@ class RestrictedNames 'pop3', 'postmaster', 'pricing', - 'privacy', 'root', 'sales', 'security', @@ -96,7 +82,6 @@ class RestrictedNames 'sys', 'sysadmin', 'system', - 'terms', 'tutorial', 'tutorials', 'usenet', @@ -121,34 +106,65 @@ class RestrictedNames 'account', 'api', 'auth', + 'bartender', 'broadcast', 'broadcaster', + 'booth', + 'bouncer', + 'c', 'css', 'checkpoint', 'collection', 'collections', - 'c', + 'costar', + 'costars', 'cdn', + 'd', 'dashboard', 'deck', + 'dev', + 'developer', + 'developers', 'discover', + 'discovers', + 'dj', + 'doc', 'docs', + 'docs', + 'drive', + 'driver', 'error', 'explore', + 'font', 'fonts', + 'gdpr', 'home', 'help', 'helpcenter', + 'help-center', + 'help_center', + 'help_center_', + 'help-center-', + 'help-center_', + 'help_center-', 'i', 'img', + 'imgs', + 'image', + 'images', 'js', + 'legal', 'live', 'login', 'logout', 'media', + 'menu', 'official', 'p', + 'photo', + 'photos', 'password', + 'privacy', 'reset', 'report', 'reports', @@ -161,10 +177,14 @@ class RestrictedNames 'statuses', 'site', 'sites', + 'stage', 'static', 'story', 'stories', 'support', + 'svg', + 'svgs', + 'terms', 'telescope', 'timeline', 'timelines', @@ -174,9 +194,11 @@ class RestrictedNames 'username', 'usernames', 'vendor', + 'waiter', 'ws', 'wss', 'www', + 'valet', '400', '401', '403',