]> BookStack Code Mirror - bookstack/blobdiff - app/Uploads/UserAvatars.php
added routes for zip export
[bookstack] / app / Uploads / UserAvatars.php
index 9692b3f38aff75936355c2c57143727c16067b80..c623247352b17234cd60168fb7686f19375478bc 100644 (file)
@@ -56,7 +56,7 @@ class UserAvatars
     /**
      * Destroy all user avatars uploaded to the given user.
      */
-    public function destroyAllForUser(User $user)
+    public function destroyAllForUser(User $user): void
     {
         $profileImages = Image::query()->where('type', '=', 'user')
             ->where('uploaded_to', '=', $user->id)
@@ -70,7 +70,7 @@ class UserAvatars
     /**
      * Save an avatar image from an external service.
      *
-     * @throws Exception
+     * @throws HttpFetchException
      */
     protected function saveAvatarImage(User $user, int $size = 500): Image
     {
@@ -114,18 +114,20 @@ class UserAvatars
         try {
             $client = $this->http->buildClient(5);
             $response = $client->sendRequest(new Request('GET', $url));
-            $imageData = (string) $response->getBody();
+            if ($response->getStatusCode() !== 200) {
+                throw new HttpFetchException(trans('errors.cannot_get_image_from_url', ['url' => $url]));
+            }
+
+            return (string) $response->getBody();
         } catch (ClientExceptionInterface $exception) {
             throw new HttpFetchException(trans('errors.cannot_get_image_from_url', ['url' => $url]), $exception->getCode(), $exception);
         }
-
-        return $imageData;
     }
 
     /**
      * Check if fetching external avatars is enabled.
      */
-    protected function avatarFetchEnabled(): bool
+    public function avatarFetchEnabled(): bool
     {
         $fetchUrl = $this->getAvatarUrl();
 
@@ -135,7 +137,7 @@ class UserAvatars
     /**
      * Get the URL to fetch avatars from.
      */
-    protected function getAvatarUrl(): string
+    public function getAvatarUrl(): string
     {
         $configOption = config('services.avatar_url');
         if ($configOption === false) {