From 02edd19d4d875956ae20251a2f0fbb200dd13f82 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Fri, 2 Dec 2022 02:45:35 -0700 Subject: [PATCH] Update Avatar pipeline, fix cloud storage media_path --- app/Console/Commands/AvatarStorage.php | 4 ++-- app/Jobs/AvatarPipeline/AvatarOptimize.php | 3 ++- app/Services/MediaStorageService.php | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/Console/Commands/AvatarStorage.php b/app/Console/Commands/AvatarStorage.php index 4ebbc26d8..054802f42 100644 --- a/app/Console/Commands/AvatarStorage.php +++ b/app/Console/Commands/AvatarStorage.php @@ -196,8 +196,8 @@ class AvatarStorage extends Command continue; } $newMediaPath = $disk->put($newPath, $existing); - $avatar->media_path = $newMediaPath; - $avatar->cdn_url = $disk->url($newMediaPath); + $avatar->media_path = $newPath; + $avatar->cdn_url = $disk->url($newPath); $avatar->save(); } diff --git a/app/Jobs/AvatarPipeline/AvatarOptimize.php b/app/Jobs/AvatarPipeline/AvatarOptimize.php index cae4456e8..4464dff4e 100644 --- a/app/Jobs/AvatarPipeline/AvatarOptimize.php +++ b/app/Jobs/AvatarPipeline/AvatarOptimize.php @@ -93,8 +93,9 @@ class AvatarOptimize implements ShouldQueue $base = 'cache/avatars/' . $avatar->profile_id; $disk = Storage::disk(config('filesystems.cloud')); $disk->deleteDirectory($base); - $path = $base . '/' . 'a' . strtolower(Str::random(random_int(3,6))) . $avatar->change_count . '.' . pathinfo($avatar->media_path, PATHINFO_EXTENSION); + $path = $base . '/' . 'avatar_' . strtolower(Str::random(random_int(3,6))) . $avatar->change_count . '.' . pathinfo($avatar->media_path, PATHINFO_EXTENSION); $url = $disk->put($path, Storage::get($avatar->media_path)); + $avatar->media_path = $path; $avatar->cdn_url = $disk->url($path); $avatar->save(); Storage::delete($avatar->media_path); diff --git a/app/Services/MediaStorageService.php b/app/Services/MediaStorageService.php index 8dd8319e7..016700d0c 100644 --- a/app/Services/MediaStorageService.php +++ b/app/Services/MediaStorageService.php @@ -229,7 +229,7 @@ class MediaStorageService { $base = ($local ? 'public/cache/' : 'cache/') . 'avatars/' . $avatar->profile_id; $ext = $head['mime'] == 'image/jpeg' ? 'jpg' : 'png'; - $path = Str::random(20) . '_avatar.' . $ext; + $path = 'avatar_' . strtolower(Str::random(random_int(3,6))) . '.' . $ext; $tmpBase = storage_path('app/remcache/'); $tmpPath = 'avatar_' . $avatar->profile_id . '-' . $path; $tmpName = $tmpBase . $tmpPath;