From 008476308227950046405c729dc90d783183fbfb Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Fri, 13 Oct 2017 12:53:27 +0100 Subject: [PATCH] Save a web archive link during process bookmark job --- app/Jobs/ProcessBookmark.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/app/Jobs/ProcessBookmark.php b/app/Jobs/ProcessBookmark.php index a4c75926..1afcc94d 100644 --- a/app/Jobs/ProcessBookmark.php +++ b/app/Jobs/ProcessBookmark.php @@ -4,6 +4,7 @@ namespace App\Jobs; use App\Bookmark; use Ramsey\Uuid\Uuid; +use GuzzleHttp\Client; use Illuminate\Bus\Queueable; use Spatie\Image\Manipulations; use Spatie\Browsershot\Browsershot; @@ -33,13 +34,24 @@ class ProcessBookmark implements ShouldQueue * * @return void */ - public function handle(Browsershot $browsershot) + public function handle(Browsershot $browsershot, Client $client) { + //save a local screenshot $uuid = Uuid::uuid4(); $browsershot->url($this->bookmark->url) ->windowSize(960, 640) ->save(public_path() . '/assets/img/bookmarks/' . $uuid . '.png'); $this->bookmark->screenshot = $uuid; + + //get an internet archive link + $response = $client->request('GET', 'https://web.archive.org/save/' . $this->bookmark->url); + if ($response->hasHeader('Content-Location')) { + if (starts_with($response->getHeader('Content-Location'), '/web')) { + $this->bookmark->archive = $response->getHeader('Content-Location'); + } + } + + //save $this->bookmark->save(); } }