Skip to content

Commit

Permalink
fix ensureDirectoryExists uses storage disk (#27)
Browse files Browse the repository at this point in the history
* fix: ensureDirectoryExists uses storage disk

* ignore phpunit cache

* chore: cleanup
  • Loading branch information
sweptsquash committed May 1, 2024
1 parent ac0a246 commit a7cbaac
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.idea
.phpunit.cache/*
.phpunit.result.cache
build
composer.lock
Expand Down
12 changes: 5 additions & 7 deletions src/Http/Controllers/LaravelOpenGraphImageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand All @@ -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);
Expand Down

0 comments on commit a7cbaac

Please sign in to comment.