Update Avatar pipeline, fix cloud storage media_path

This commit is contained in:
Daniel Supernault 2022-12-02 02:45:35 -07:00
parent 9a89a2b751
commit 02edd19d4d
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7
3 changed files with 5 additions and 4 deletions

View file

@ -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();
}

View file

@ -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);

View file

@ -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;