]> BookStack Code Mirror - bookstack/blobdiff - app/Uploads/FileStorage.php
Lexical: Updated tests for node changes
[bookstack] / app / Uploads / FileStorage.php
index 278484e519de0629b8a29c0c5d4ee98a158b6b71..e6ac368d000c20cd33c4b038438c5cc12228ec7a 100644 (file)
@@ -5,6 +5,7 @@ namespace BookStack\Uploads;
 use BookStack\Exceptions\FileUploadException;
 use Exception;
 use Illuminate\Contracts\Filesystem\Filesystem as Storage;
+use Illuminate\Filesystem\FilesystemAdapter;
 use Illuminate\Filesystem\FilesystemManager;
 use Illuminate\Support\Facades\Log;
 use Illuminate\Support\Str;
@@ -70,6 +71,26 @@ class FileStorage
         return $filePath;
     }
 
+    /**
+     * Check whether the configured storage is remote from the host of this app.
+     */
+    public function isRemote(): bool
+    {
+        return $this->getStorageDiskName() === 's3';
+    }
+
+    /**
+     * Get the actual path on system for the given relative file path.
+     */
+    public function getSystemPath(string $filePath): string
+    {
+        if ($this->isRemote()) {
+            return '';
+        }
+
+        return storage_path('uploads/files/' . ltrim($this->adjustPathForStorageDisk($filePath), '/'));
+    }
+
     /**
      * Get the storage that will be used for storing files.
      */
@@ -83,7 +104,7 @@ class FileStorage
      */
     protected function getStorageDiskName(): string
     {
-        $storageType = config('filesystems.attachments');
+        $storageType = trim(strtolower(config('filesystems.attachments')));
 
         // Change to our secure-attachment disk if any of the local options
         // are used to prevent escaping that location.