From c8ccebfebcf3dc480ecc23853e9ac1fd46e56a36 Mon Sep 17 00:00:00 2001 From: Richard Dern Date: Wed, 17 Apr 2024 15:29:28 +0200 Subject: [PATCH] Completed LinkBundleCreator --- .../Creators/LinkBundleCreator.php | 35 +++++++++++++------ 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/app/Services/BundleCreator/Creators/LinkBundleCreator.php b/app/Services/BundleCreator/Creators/LinkBundleCreator.php index ea6a412..b0e513b 100644 --- a/app/Services/BundleCreator/Creators/LinkBundleCreator.php +++ b/app/Services/BundleCreator/Creators/LinkBundleCreator.php @@ -4,6 +4,7 @@ use App\Classes\Bundle; use App\Exceptions\BundleAlreadyExists; +use App\Services\Browser; use Illuminate\Filesystem\FilesystemAdapter; use function Laravel\Prompts\text; @@ -22,11 +23,10 @@ public function __construct(protected ?array $data, protected FilesystemAdapter */ public function createBundle(): string { - $url = $this->data['url']; - $hash = md5($url); - $date = now(); - $path = sprintf('%s/%s/%s', static::$section, $date->format('Y/m/d'), $hash); - + $url = $this->data['url']; + $hash = md5($url); + $date = now(); + $path = sprintf('%s/%s/%s', static::$section, $date->format('Y/m/d'), $hash); $bundle = new Bundle($path, $this->disk); if ($bundle->exists()) { @@ -35,11 +35,26 @@ public function createBundle(): string ); } - $bundle->markdown()->set(''); - // $bundle->metadata()->set([ - // 'title' => $title, - // 'date' => $date->toIso8601String(), - // ]); + $browser = new Browser($url); + + $browser->go(); + + $screenshot = $browser->getScreenshot(); + $title = $browser->getTitle(); + $description = $browser->getDescription(); + + $ref = $bundle->attachments('images')->addToHistory('screenshot', [ + 'contents' => $screenshot, + 'filename' => 'screenshot.jpg', + ]); + + $bundle->metadata()->set([ + 'title' => $title, + 'date' => $date->toIso8601String(), + 'cover' => $ref, + ]); + + $bundle->markdown()->set('> ' . $description . "\n\n"); $bundle->save();