2017-10-13 12:31:31 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Jobs;
|
|
|
|
|
|
|
|
use App\Bookmark;
|
|
|
|
use Ramsey\Uuid\Uuid;
|
2017-10-13 12:53:27 +01:00
|
|
|
use GuzzleHttp\Client;
|
2017-10-13 12:31:31 +01:00
|
|
|
use Illuminate\Bus\Queueable;
|
|
|
|
use Spatie\Image\Manipulations;
|
|
|
|
use Spatie\Browsershot\Browsershot;
|
|
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
|
|
|
|
|
|
class ProcessBookmark implements ShouldQueue
|
|
|
|
{
|
|
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
|
|
|
|
protected $bookmark;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new job instance.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __construct(Bookmark $bookmark)
|
|
|
|
{
|
|
|
|
$this->bookmark = $bookmark;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the job.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2017-10-13 12:53:27 +01:00
|
|
|
public function handle(Browsershot $browsershot, Client $client)
|
2017-10-13 12:31:31 +01:00
|
|
|
{
|
2017-10-13 12:53:27 +01:00
|
|
|
//save a local screenshot
|
2017-10-13 12:31:31 +01:00
|
|
|
$uuid = Uuid::uuid4();
|
|
|
|
$browsershot->url($this->bookmark->url)
|
|
|
|
->windowSize(960, 640)
|
|
|
|
->save(public_path() . '/assets/img/bookmarks/' . $uuid . '.png');
|
|
|
|
$this->bookmark->screenshot = $uuid;
|
2017-10-13 12:53:27 +01:00
|
|
|
|
|
|
|
//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
|
2017-10-13 12:31:31 +01:00
|
|
|
$this->bookmark->save();
|
|
|
|
}
|
|
|
|
}
|