From 280f63dc6aaa0892251dea83e0747dbc889b9403 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Fri, 31 Jan 2025 00:13:37 -0700 Subject: [PATCH 1/2] Update MediaStorageService, handle local media deletes after successful S3 upload --- app/Services/MediaStorageService.php | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/app/Services/MediaStorageService.php b/app/Services/MediaStorageService.php index 87bb9a586..1daee63b6 100644 --- a/app/Services/MediaStorageService.php +++ b/app/Services/MediaStorageService.php @@ -19,7 +19,7 @@ class MediaStorageService public static function store(Media $media) { if ((bool) config_cache('pixelfed.cloud_storage') == true) { - (new self())->cloudStore($media); + (new self)->cloudStore($media); } } @@ -31,19 +31,19 @@ class MediaStorageService } if ((bool) config_cache('pixelfed.cloud_storage') == true) { - return (new self())->cloudMove($media); + return (new self)->cloudMove($media); } } public static function avatar($avatar, $local = false, $skipRecentCheck = false) { - return (new self())->fetchAvatar($avatar, $local, $skipRecentCheck); + return (new self)->fetchAvatar($avatar, $local, $skipRecentCheck); } public static function head($url) { - $c = new Client(); + $c = new Client; try { $r = $c->request('HEAD', $url); } catch (RequestException $e) { @@ -75,10 +75,10 @@ class MediaStorageService { if ($media->remote_media == true) { if (config('media.storage.remote.cloud')) { - (new self())->remoteToCloud($media); + (new self)->remoteToCloud($media); } } else { - (new self())->localToCloud($media); + (new self)->localToCloud($media); } } @@ -102,6 +102,18 @@ class MediaStorageService $media->optimized_url = $url; $media->replicated_at = now(); $media->save(); + if ((bool) config_cache('pixelfed.cloud_storage') && (bool) config('media.delete_local_after_cloud')) { + $s3Domain = config('filesystems.disks.s3.url') ?? config('filesystems.disks.s3.endpoint'); + if (str_contains($url, $s3Domain)) { + if (file_exists($path)) { + unlink($path); + } + + if (file_exists($thumb)) { + unlink($thumb); + } + } + } if ($media->status_id) { Cache::forget('status:transformer:media:attachments:'.$media->status_id); MediaService::del($media->status_id); From 52f83630242304d65a067970db171d69e3065ef9 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Fri, 31 Jan 2025 00:14:12 -0700 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index abed4f19d..c805e84ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ - Update AP Helpers, fix comment bug ([22eae69f](https://github.com/pixelfed/pixelfed/commit/22eae69f)) - Update ComposeController, add max_media_attachments attribute ([17918cbe](https://github.com/pixelfed/pixelfed/commit/17918cbe)) - Fix GroupController, move groups enabled check to each method to fix route:list ([f260572e](https://github.com/pixelfed/pixelfed/commit/f260572e)) +- Update MediaStorageService, handle local media deletes after successful S3 upload ([280f63dc](https://github.com/pixelfed/pixelfed/commit/280f63dc)) - ([](https://github.com/pixelfed/pixelfed/commit/)) ## [v0.12.4 (2024-11-08)](https://github.com/pixelfed/pixelfed/compare/v0.12.4...dev)