Repo for the search and displace core module including the interface to select files and search and displace operations to run on them. https://searchanddisplace.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

54 lines
1.5 KiB

<?php
namespace App\SearchDisplace\Ingest;
use App\Events\IngestDocumentReceived;
use Illuminate\Support\Facades\Storage;
class HandleReceivedDocument
{
protected $id;
protected $content;
protected $status;
public function __construct($payload)
{
$this->id = $payload['data']['id'];
$this->content = $payload['data']['content'];
$this->status = $payload['data']['status'];
}
public function handle()
{
$storage = Storage::disk('local');
$fileName = 'document';
// The .md extension signals the success status, the lack of signals the fail status.
if ($this->status === 'success') {
$fileName = $fileName . '.md';
}
$dir = "contracts/$this->id";
try {
$storage->makeDirectory($dir);
$storage->put("$dir/$fileName", $this->content['document']);
foreach ($this->content['images'] as $image) {
$name = $image['name'];
$type = $image['type'];
$contents = $image['contents'];
$contents = str_replace('data:image/' . $type . ';base64,', '', $contents);
$storage->put("$dir/$name.$type", base64_decode($contents));
}
IngestDocumentReceived::dispatch($this->id);
} catch (\Exception $exception) {
\Illuminate\Support\Facades\Log::info('Exception: ' . $exception->getTraceAsString());
}
}
}