+ /**
+ * Check if the given path exists in the local secure image system.
+ * Returns false if local_secure is not in use.
+ */
+ 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
+ && strpos($disk->getMimetype($imagePath), 'image/') === 0;
+ }
+
+ /**
+ * For the given path, if existing, provide a response that will stream the image contents.
+ */
+ public function streamImageFromStorageResponse(string $imageType, string $path): StreamedResponse
+ {
+ $disk = $this->getStorageDisk($imageType);
+
+ return $disk->response($path);
+ }
+
+ /**
+ * Check if the given image extension is supported by BookStack.
+ * The extension must not be altered in this function. This check should provide a guarantee
+ * that the provided extension is safe to use for the image to be saved.
+ */
+ public static function isExtensionSupported(string $extension): bool
+ {
+ return in_array($extension, static::$supportedExtensions);
+ }
+