diff --git a/app/Services/MediaStorageService.php b/app/Services/MediaStorageService.php index ca1e93e4a..eac7da1a7 100644 --- a/app/Services/MediaStorageService.php +++ b/app/Services/MediaStorageService.php @@ -248,7 +248,7 @@ class MediaStorageService { $avatar->media_path = $base . $path; $avatar->is_remote = true; - $avatar->cdn_url = $permalink; + $avatar->cdn_url = $local ? config('app.url') . $permalink : $permalink; $avatar->size = $head['length']; $avatar->change_count = $avatar->change_count + 1; $avatar->last_fetched_at = now(); diff --git a/database/migrations/2022_10_09_043758_fix_cdn_url_in_avatars_table.php b/database/migrations/2022_10_09_043758_fix_cdn_url_in_avatars_table.php new file mode 100644 index 000000000..65b19496b --- /dev/null +++ b/database/migrations/2022_10_09_043758_fix_cdn_url_in_avatars_table.php @@ -0,0 +1,41 @@ +chunk(50, function($avatars) use($baseUrl) { + foreach($avatars as $avatar) { + if(substr($avatar->cdn_url, 0, 23) === '/storage/cache/avatars/') { + $avatar->cdn_url = $baseUrl . $avatar->cdn_url; + $avatar->save(); + } + Cache::forget('avatar:' . $avatar->profile_id); + AccountService::del($avatar->profile_id); + } + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + } +}