]> BookStack Code Mirror - bookstack/blobdiff - app/Uploads/AttachmentService.php
respective book and chapter structure added.
[bookstack] / app / Uploads / AttachmentService.php
index ec02182bb118624fda0be7cdabbf7fde5eecadab..bd319fbd795af717c4c026d63b9b8bc58ea7fabd 100644 (file)
@@ -4,12 +4,11 @@ namespace BookStack\Uploads;
 
 use BookStack\Exceptions\FileUploadException;
 use Exception;
-use Illuminate\Contracts\Filesystem\FileNotFoundException;
 use Illuminate\Contracts\Filesystem\Filesystem as Storage;
 use Illuminate\Filesystem\FilesystemManager;
 use Illuminate\Support\Facades\Log;
 use Illuminate\Support\Str;
-use League\Flysystem\Util;
+use League\Flysystem\WhitespacePathNormalizer;
 use Symfony\Component\HttpFoundation\File\UploadedFile;
 
 class AttachmentService
@@ -41,7 +40,7 @@ class AttachmentService
 
         // Change to our secure-attachment disk if any of the local options
         // are used to prevent escaping that location.
-        if ($storageType === 'local' || $storageType === 'local_secure') {
+        if ($storageType === 'local' || $storageType === 'local_secure' || $storageType === 'local_secure_restricted') {
             $storageType = 'local_secure_attachments';
         }
 
@@ -54,7 +53,7 @@ class AttachmentService
      */
     protected function adjustPathForStorageDisk(string $path): string
     {
-        $path = Util::normalizePath(str_replace('uploads/files/', '', $path));
+        $path = (new WhitespacePathNormalizer())->normalizePath(str_replace('uploads/files/', '', $path));
 
         if ($this->getStorageDiskName() === 'local_secure_attachments') {
             return $path;
@@ -64,25 +63,21 @@ class AttachmentService
     }
 
     /**
-     * Get an attachment from storage.
+     * Stream an attachment from storage.
      *
-     * @throws FileNotFoundException
+     * @return resource|null
      */
-    public function getAttachmentFromStorage(Attachment $attachment): string
+    public function streamAttachmentFromStorage(Attachment $attachment)
     {
-        return $this->getStorageDisk()->get($this->adjustPathForStorageDisk($attachment->path));
+        return $this->getStorageDisk()->readStream($this->adjustPathForStorageDisk($attachment->path));
     }
 
     /**
-     * Stream an attachment from storage.
-     *
-     * @return resource|null
-     * @throws FileNotFoundException
+     * Read the file size of an attachment from storage, in bytes.
      */
-    public function streamAttachmentFromStorage(Attachment $attachment)
+    public function getAttachmentFileSize(Attachment $attachment): int
     {
-
-        return $this->getStorageDisk()->readStream($this->adjustPathForStorageDisk($attachment->path));
+        return $this->getStorageDisk()->size($this->adjustPathForStorageDisk($attachment->path));
     }
 
     /**