From b356cfaea19a71339d38136440ad394e4bfb8f81 Mon Sep 17 00:00:00 2001 From: Josef Citrine Date: Sat, 12 Nov 2016 21:38:03 +0000 Subject: [PATCH] Server should now check local avatar file instead of URL --- .../Controllers/Api/Web/ArtistsController.php | 14 ++------------ app/Models/User.php | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 12 deletions(-) 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. *