1
0

Completed LinkBundleCreator

This commit is contained in:
Richard Dern 2024-04-17 15:29:28 +02:00
parent 2100fec73f
commit c8ccebfebc

View File

@ -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();