Преглед изворни кода

Merge pull request #5650 from pixelfed/staging

Staging
daniel пре 5 месеци
родитељ
комит
ab49e5cf9a
2 измењених фајлова са 19 додато и 6 уклоњено
  1. 1 0
      CHANGELOG.md
  2. 18 6
      app/Services/MediaStorageService.php

+ 1 - 0
CHANGELOG.md

@@ -39,6 +39,7 @@
 - Update AP Helpers, fix comment bug ([22eae69f](https://github.com/pixelfed/pixelfed/commit/22eae69f))
 - 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))
 - 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))
 - 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/))
 -  ([](https://github.com/pixelfed/pixelfed/commit/))
 
 
 ## [v0.12.4 (2024-11-08)](https://github.com/pixelfed/pixelfed/compare/v0.12.4...dev)
 ## [v0.12.4 (2024-11-08)](https://github.com/pixelfed/pixelfed/compare/v0.12.4...dev)

+ 18 - 6
app/Services/MediaStorageService.php

@@ -19,7 +19,7 @@ class MediaStorageService
     public static function store(Media $media)
     public static function store(Media $media)
     {
     {
         if ((bool) config_cache('pixelfed.cloud_storage') == true) {
         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) {
         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)
     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)
     public static function head($url)
     {
     {
-        $c = new Client();
+        $c = new Client;
         try {
         try {
             $r = $c->request('HEAD', $url);
             $r = $c->request('HEAD', $url);
         } catch (RequestException $e) {
         } catch (RequestException $e) {
@@ -75,10 +75,10 @@ class MediaStorageService
     {
     {
         if ($media->remote_media == true) {
         if ($media->remote_media == true) {
             if (config('media.storage.remote.cloud')) {
             if (config('media.storage.remote.cloud')) {
-                (new self())->remoteToCloud($media);
+                (new self)->remoteToCloud($media);
             }
             }
         } else {
         } else {
-            (new self())->localToCloud($media);
+            (new self)->localToCloud($media);
         }
         }
     }
     }
 
 
@@ -102,6 +102,18 @@ class MediaStorageService
         $media->optimized_url = $url;
         $media->optimized_url = $url;
         $media->replicated_at = now();
         $media->replicated_at = now();
         $media->save();
         $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) {
         if ($media->status_id) {
             Cache::forget('status:transformer:media:attachments:'.$media->status_id);
             Cache::forget('status:transformer:media:attachments:'.$media->status_id);
             MediaService::del($media->status_id);
             MediaService::del($media->status_id);