From a7cbaac4a28514c440b0863f44113b6f41eda14e Mon Sep 17 00:00:00 2001 From: Stewie Marsh Date: Wed, 1 May 2024 10:14:14 +0100 Subject: [PATCH] fix `ensureDirectoryExists` uses storage disk (#27) * fix: ensureDirectoryExists uses storage disk * ignore phpunit cache * chore: cleanup --- .gitignore | 1 + .../Controllers/LaravelOpenGraphImageController.php | 12 +++++------- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 818cfd7..fff7798 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .idea +.phpunit.cache/* .phpunit.result.cache build composer.lock diff --git a/src/Http/Controllers/LaravelOpenGraphImageController.php b/src/Http/Controllers/LaravelOpenGraphImageController.php index 397ee9c..a7b5c4f 100644 --- a/src/Http/Controllers/LaravelOpenGraphImageController.php +++ b/src/Http/Controllers/LaravelOpenGraphImageController.php @@ -3,7 +3,6 @@ namespace Vormkracht10\LaravelOpenGraphImage\Http\Controllers; use Illuminate\Http\Request; -use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\View; use Spatie\Browsershot\Browsershot; @@ -97,12 +96,12 @@ public function getImageType() public function ensureDirectoryExists() { - if (! File::isDirectory($this->getStoragePath())) { - File::makeDirectory($this->getStoragePath(), 0777, true); + if (! $this->getStorageDisk()->exists($this->getStoragePath())) { + $this->getStorageDisk()->makeDirectory($this->getStoragePath()); } } - public function getScreenshot($html, $filename) + public function getScreenshot($html) { $browsershot = Browsershot::html($html) ->noSandbox() @@ -118,15 +117,14 @@ public function getScreenshot($html, $filename) $browsershot = $browsershot->setNpmBinary(config('open-graph-image.paths.npm')); } - return $browsershot - ->screenshot($this->getStorageFilePath($filename)); + return $browsershot->screenshot(); } public function saveOpenGraphImage($html, $filename) { $this->ensureDirectoryExists(); - $screenshot = $this->getScreenshot($html, $filename); + $screenshot = $this->getScreenshot($html); $this->getStorageDisk() ->put($this->getStorageFilePath($filename), $screenshot);