X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/4360da03d414cc926dde3d79e22e6e35f85838e1..refs/pull/3043/head:/app/Uploads/ImageService.php diff --git a/app/Uploads/ImageService.php b/app/Uploads/ImageService.php index eb2fc57b8..b8477eb40 100644 --- a/app/Uploads/ImageService.php +++ b/app/Uploads/ImageService.php @@ -6,16 +6,16 @@ use BookStack\Exceptions\ImageUploadException; use ErrorException; use Exception; use Illuminate\Contracts\Cache\Repository as Cache; -use Illuminate\Contracts\Filesystem\Factory as FileSystem; use Illuminate\Contracts\Filesystem\FileNotFoundException; -use Illuminate\Contracts\Filesystem\Filesystem as FileSystemInstance; use Illuminate\Contracts\Filesystem\Filesystem as Storage; +use Illuminate\Filesystem\FilesystemAdapter; +use Illuminate\Filesystem\FilesystemManager; use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\Log; use Illuminate\Support\Str; use Intervention\Image\Exception\NotSupportedException; use Intervention\Image\ImageManager; use League\Flysystem\Util; -use Log; use Psr\SimpleCache\InvalidArgumentException; use Symfony\Component\HttpFoundation\File\UploadedFile; use Symfony\Component\HttpFoundation\StreamedResponse; @@ -33,7 +33,7 @@ class ImageService /** * ImageService constructor. */ - public function __construct(Image $image, ImageManager $imageTool, FileSystem $fileSystem, Cache $cache) + public function __construct(Image $image, ImageManager $imageTool, FilesystemManager $fileSystem, Cache $cache) { $this->image = $image; $this->imageTool = $imageTool; @@ -44,7 +44,7 @@ class ImageService /** * Get the storage that will be used for storing images. */ - protected function getStorageDisk(string $imageType = ''): FileSystemInstance + protected function getStorageDisk(string $imageType = ''): Storage { return $this->fileSystem->disk($this->getStorageDiskName($imageType)); } @@ -232,6 +232,7 @@ class ImageService * Get the thumbnail for an image. * If $keepRatio is true only the width will be used. * Checks the cache then storage to avoid creating / accessing the filesystem on every check. + * * @throws Exception * @throws InvalidArgumentException */ @@ -271,7 +272,7 @@ class ImageService { try { $thumb = $this->imageTool->make($imageData); - } catch (ErrorException | NotSupportedException $e) { + } catch (ErrorException|NotSupportedException $e) { throw new ImageUploadException(trans('errors.cannot_create_thumbs')); } @@ -351,7 +352,7 @@ class ImageService /** * Check whether a folder is empty. */ - protected function isFolderEmpty(FileSystemInstance $storage, string $path): bool + protected function isFolderEmpty(Storage $storage, string $path): bool { $files = $storage->files($path); $folders = $storage->directories($path); @@ -436,10 +437,12 @@ class ImageService */ public function pathExistsInLocalSecure(string $imagePath): bool { + /** @var FilesystemAdapter $disk */ $disk = $this->getStorageDisk('gallery'); // Check local_secure is active return $this->usingSecureImages() + && $disk instanceof FilesystemAdapter // Check the image file exists && $disk->exists($imagePath) // Check the file is likely an image file @@ -452,6 +455,7 @@ class ImageService public function streamImageFromStorageResponse(string $imageType, string $path): StreamedResponse { $disk = $this->getStorageDisk($imageType); + return $disk->response($path); }