]> BookStack Code Mirror - bookstack/blobdiff - app/Services/ImageService.php
orthography
[bookstack] / app / Services / ImageService.php
index 6686082eefea30073229496509a38c6ca0c795ac..c2e915e2d91e64353bf303eb40dea4f0c83c3553 100644 (file)
@@ -31,6 +31,23 @@ class ImageService extends UploadService
         parent::__construct($fileSystem);
     }
 
+    /**
+     * Get the storage that will be used for storing images.
+     * @param string $type
+     * @return \Illuminate\Contracts\Filesystem\Filesystem
+     */
+    protected function getStorage($type = '')
+    {
+        $storageType = config('filesystems.default');
+
+        // Override default location if set to local public to ensure not visible.
+        if ($type === 'system' && $storageType === 'local_secure') {
+            $storageType = 'local';
+        }
+
+        return $this->fileSystem->disk($storageType);
+    }
+
     /**
      * Saves a new image from an upload.
      * @param UploadedFile $uploadedFile
@@ -119,7 +136,7 @@ class ImageService extends UploadService
      */
     private function saveNew($imageName, $imageData, $type, $uploadedTo = 0)
     {
-        $storage = $this->getStorage();
+        $storage = $this->getStorage($type);
         $secureUploads = setting('app-secure-images');
         $imageName = str_replace(' ', '-', $imageName);
 
@@ -175,7 +192,8 @@ class ImageService extends UploadService
      * @param Image $image
      * @return boolean
      */
-    protected function isGif(Image $image) {
+    protected function isGif(Image $image)
+    {
         return strtolower(pathinfo($this->getPath($image), PATHINFO_EXTENSION)) === 'gif';
     }
 
@@ -205,7 +223,7 @@ class ImageService extends UploadService
             return $this->getPublicUrl($thumbFilePath);
         }
 
-        $storage = $this->getStorage();
+        $storage = $this->getStorage($image->type);
         if ($storage->exists($thumbFilePath)) {
             return $this->getPublicUrl($thumbFilePath);
         }
@@ -287,8 +305,9 @@ class ImageService extends UploadService
     /**
      * Save a gravatar image and set a the profile image for a user.
      * @param User $user
-     * @param int  $size
+     * @param int $size
      * @return mixed
+     * @throws Exception
      */
     public function saveUserGravatar(User $user, $size = 500)
     {