From 37dbb3de295847ca8ac50e2ea57bade7bd02dadc Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Fri, 5 Feb 2021 21:00:29 -0700 Subject: [PATCH 1/5] Update MediaStorageService, dispatch deletes to MediaDeletePipeline --- .../MediaPipeline/MediaDeletePipeline.php | 67 +++++++++++++++++++ app/Services/MediaStorageService.php | 9 +++ app/Util/Sentiment/Bouncer.php | 6 ++ 3 files changed, 82 insertions(+) create mode 100644 app/Jobs/MediaPipeline/MediaDeletePipeline.php diff --git a/app/Jobs/MediaPipeline/MediaDeletePipeline.php b/app/Jobs/MediaPipeline/MediaDeletePipeline.php new file mode 100644 index 000000000..9d89f9449 --- /dev/null +++ b/app/Jobs/MediaPipeline/MediaDeletePipeline.php @@ -0,0 +1,67 @@ +media = $media; + } + + public function handle() + { + $media = $this->media; + $path = $media->media_path; + $thumb = $media->thumbnail_path; + + if(!$path) { + return 1; + } + + $e = explode('/', $path); + array_pop($e); + $i = implode('/', $e); + + if(config('pixelfed.cloud_storage') == true) { + $disk = Storage::disk(config('filesystems.cloud')); + if($disk->exists($path)) { + $disk->delete($path); + } + if($disk->exists($thumb)) { + $disk->delete($thumb); + } + + if(count($e) > 4 && count($disk->files($i)) == 0) { + $disk->deleteDirectory($i); + } + } + + $disk = Storage::disk(config('filesystems.local')); + if($disk->exists($path)) { + $disk->delete($path); + } + if($disk->exists($thumb)) { + $disk->delete($thumb); + } + if(count($e) > 4 && count($disk->files($i)) == 0) { + $disk->deleteDirectory($i); + } + + return 1; + } + +} \ No newline at end of file diff --git a/app/Services/MediaStorageService.php b/app/Services/MediaStorageService.php index ec718d0eb..5d301dd9c 100644 --- a/app/Services/MediaStorageService.php +++ b/app/Services/MediaStorageService.php @@ -14,6 +14,7 @@ use App\User; use GuzzleHttp\Client; use App\Http\Controllers\AvatarController; use GuzzleHttp\Exception\RequestException; +use App\Jobs\MediaPipeline\MediaDeletePipeline; class MediaStorageService { @@ -227,4 +228,12 @@ class MediaStorageService { unlink($tmpName); } + + public static function delete(Media $media, $confirm = false) + { + if(!$confirm) { + return; + } + MediaDeletePipeline::dispatch($media); + } } \ No newline at end of file diff --git a/app/Util/Sentiment/Bouncer.php b/app/Util/Sentiment/Bouncer.php index 5841cb4d1..9a1e8ddef 100644 --- a/app/Util/Sentiment/Bouncer.php +++ b/app/Util/Sentiment/Bouncer.php @@ -18,6 +18,12 @@ class Bouncer { $exemptionKey = 'pf:bouncer_v0:exemption_by_pid:' . $status->profile_id; $exemptionTtl = now()->addDays(12); + if( $status->in_reply_to_id != null && + $status->in_reply_to_profile_id == $status->profile_id + ) { + return; + } + $exemption = Cache::remember($exemptionKey, $exemptionTtl, function() use($status) { $uid = $status->profile->user_id; $ids = AccountInterstitial::whereUserId($uid) From ab5469ff707acffb717fa2e2933150d49e7c5a03 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Fri, 5 Feb 2021 21:04:34 -0700 Subject: [PATCH 2/5] Update ComposeController, use MediaStorageService for media deletes --- app/Http/Controllers/ComposeController.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/ComposeController.php b/app/Http/Controllers/ComposeController.php index d292b590b..bada3cd65 100644 --- a/app/Http/Controllers/ComposeController.php +++ b/app/Http/Controllers/ComposeController.php @@ -38,6 +38,7 @@ use App\Jobs\VideoPipeline\{ use App\Services\NotificationService; use App\Services\MediaPathService; use App\Services\MediaBlocklistService; +use App\Services\MediaStorageService; use App\Services\MediaTagService; use App\Services\ServiceService; use Illuminate\Support\Str; @@ -193,8 +194,7 @@ class ComposeController extends Controller ->whereUserId(Auth::id()) ->findOrFail($request->input('id')); - Storage::delete($media->media_path); - Storage::delete($media->thumbnail_path); + MediaStorageService::delete($media, true); $media->forceDelete(); @@ -388,6 +388,7 @@ class ComposeController extends Controller } $status->caption = strip_tags($request->caption); + $status->rendered = Autolink::create()->autolink($status->caption); $status->scope = 'draft'; $status->profile_id = $profile->id; $status->save(); From 9fd90e174b38863fa2349b6e9c202289d1345971 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Fri, 5 Feb 2021 21:05:58 -0700 Subject: [PATCH 3/5] Update StatusDeletePipeline, use StorageMediaService for media deletes --- app/Jobs/StatusPipeline/StatusDelete.php | 34 +++--------------------- 1 file changed, 3 insertions(+), 31 deletions(-) diff --git a/app/Jobs/StatusPipeline/StatusDelete.php b/app/Jobs/StatusPipeline/StatusDelete.php index 64339ff65..4f29d6b15 100644 --- a/app/Jobs/StatusPipeline/StatusDelete.php +++ b/app/Jobs/StatusPipeline/StatusDelete.php @@ -26,6 +26,7 @@ use GuzzleHttp\Client; use GuzzleHttp\Promise; use App\Util\ActivityPub\HttpSignature; use App\Services\StatusService; +use App\Services\MediaStorageService; class StatusDelete implements ShouldQueue { @@ -82,38 +83,9 @@ class StatusDelete implements ShouldQueue public function unlinkRemoveMedia($status) { foreach ($status->media as $media) { - $thumbnail = storage_path("app/{$media->thumbnail_path}"); - $photo = storage_path("app/{$media->media_path}"); - - try { - if (is_file($thumbnail)) { - unlink($thumbnail); - } - if (is_file($photo)) { - unlink($photo); - } - if( config('pixelfed.cloud_storage') == true) { - if( Str::of($media->media_path) - ->startsWith('public/') && - Storage::disk(config('filesystems.cloud')) - ->exists($media->media_path) - ) { - Storage::disk(config('filesystems.cloud')) - ->delete($media->media_path); - } - if( Str::of($media->thumbnail_path) - ->startsWith('public/') && - Storage::disk(config('filesystems.cloud')) - ->exists($media->thumbnail_path) - ) { - Storage::disk(config('filesystems.cloud')) - ->delete($media->thumbnail_path); - } - } - $media->delete(); - } catch (Exception $e) { - } + MediaStorageService::delete($media, true); } + if($status->in_reply_to_id) { DB::transaction(function() use($status) { $parent = Status::findOrFail($status->in_reply_to_id); From 1404ac6e6f4195e2698e3a21e44348d633d3a804 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Fri, 5 Feb 2021 21:09:03 -0700 Subject: [PATCH 4/5] Update Discover, allow public discover access --- app/Http/Controllers/DiscoverController.php | 4 +++- config/instance.php | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/DiscoverController.php b/app/Http/Controllers/DiscoverController.php index 25386f702..87db73ba3 100644 --- a/app/Http/Controllers/DiscoverController.php +++ b/app/Http/Controllers/DiscoverController.php @@ -37,7 +37,7 @@ class DiscoverController extends Controller public function home(Request $request) { - abort_if(!Auth::check(), 403); + abort_if(!Auth::check() && config('instance.discover.public') == false, 403); return view('discover.home'); } @@ -113,6 +113,8 @@ class DiscoverController extends Controller public function trendingApi(Request $request) { + abort_if(config('instance.discover.public') == false && !Auth::check(), 403); + $this->validate($request, [ 'range' => 'nullable|string|in:daily,monthly' ]); diff --git a/config/instance.php b/config/instance.php index 39a622351..1fa95229f 100644 --- a/config/instance.php +++ b/config/instance.php @@ -10,6 +10,7 @@ return [ ], 'discover' => [ + 'public' => env('INSTANCE_DISCOVER_PUBLIC', false), 'loops' => [ 'enabled' => env('EXP_LOOPS', false), ], From 18ee2def9244dcaedb95ea7bcf8751b6cdec0f71 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Fri, 5 Feb 2021 21:10:25 -0700 Subject: [PATCH 5/5] Update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c8aa74bc..ba6746003 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,10 @@ - Updated AccountController, add mutes and blocks endpoint to pixelfed api. ([1fb7e2b2](https://github.com/pixelfed/pixelfed/commit/1fb7e2b2)) - Updated AccountService, cache object and observe changes. ([b299da93](https://github.com/pixelfed/pixelfed/commit/b299da93)) - Updated webfinger util, fail on invalid webfinger url. Fixes ([#2613](https://github.com/pixelfed/pixelfed/issues/2613)) ([2d11317c](https://github.com/pixelfed/pixelfed/commit/2d11317c)) +- Updated MediaStorageService, dispatch deletes to MediaDeletePipeline. ([37dbb3de](https://github.com/pixelfed/pixelfed/commit/37dbb3de)) +- Updated ComposeController, use MediaStorageService for media deletes. ([ab5469ff](https://github.com/pixelfed/pixelfed/commit/ab5469ff)) +- Updated StatusDeletePipeline, use MediaStorageService for media deletes. ([9fd90e17](https://github.com/pixelfed/pixelfed/commit/9fd90e17)) +- Updated Discover, allow public discover access. ([1404ac6e](https://github.com/pixelfed/pixelfed/commit/1404ac6e)) - ([](https://github.com/pixelfed/pixelfed/commit/)) ## [v0.10.10 (2021-01-28)](https://github.com/pixelfed/pixelfed/compare/v0.10.9...v0.10.10)