diff --git a/app/Http/Controllers/Api/Web/ArtistsController.php b/app/Http/Controllers/Api/Web/ArtistsController.php index 13763726..fad81d22 100644 --- a/app/Http/Controllers/Api/Web/ArtistsController.php +++ b/app/Http/Controllers/Api/Web/ArtistsController.php @@ -172,18 +172,8 @@ class ArtistsController extends ApiControllerBase ]; } - $formatted_palette = [ - "#ffffff", - "#ffffff", - "#ffffff" - ]; - - try { - $palette = ColorThief::getPalette($user->getAvatarUrl(Image::SMALL), 2); - $formatted_palette = array_map("Helpers::rgb2hex", $palette); - } catch (Exception $e) { - // We failed to get the image, oh well - } + $palette = ColorThief::getPalette($user->getAvatarUrlLocal(Image::SMALL), 2); + $formatted_palette = array_map("Helpers::rgb2hex", $palette); $followers = Follower::where('artist_id', $user->id) ->count(); diff --git a/app/Models/User.php b/app/Models/User.php index e1097784..dd5ea924 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -273,6 +273,25 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon return Gravatar::getUrl($email, Image::$ImageTypes[$type]['width']); } + public function getAvatarUrlLocal($type = Image::NORMAL) + { + if (!$this->uses_gravatar && $this->avatar !== null) { + return $this->avatar->getFile($type); + } + + if ($this->email == "redacted@example.net") { + return Gravatar::getUrl($this->id."", Image::$ImageTypes[$type]['width'], "identicon"); + } + + $email = $this->gravatar; + + if (!strlen($email)) { + $email = $this->email; + } + + return Gravatar::getUrl($email, Image::$ImageTypes[$type]['width']); + } + /** * Get the token value for the "remember me" session. *