Browse Source

Send document back to core in HTML format

master
Alex Puiu 2 years ago
parent
commit
50ab7a6333
  1. 2
      app/Http/Controllers/IngestController.php
  2. 12
      app/Ingest/DocxAndOdtConvertor.php
  3. 6
      app/Jobs/IngestDocuments.php
  4. 20
      app/Jobs/SendToCore.php

2
app/Http/Controllers/IngestController.php

@ -10,7 +10,7 @@ class IngestController extends Controller
{
request()->validate([
'id' => 'required',
'file_result_type' => 'required|in:md,original,json',
'file_result_type' => 'required|in:html',
'mime_type' => 'required',
'document' => 'required|file',
]);

12
app/Ingest/DocxAndOdtConvertor.php

@ -13,15 +13,11 @@ class DocxAndOdtConvertor extends AbstractConvertor
*/
public function execute()
{
$this->convertToPdfWithLibreOffice();
$this->convertToHTMLWithLibreOffice();
if ( ! $this->storage->exists($this->path)) {
throw new \Exception('Failed to convert to PDF: ' . $this->path);
throw new \Exception('Failed to convert to HTML: ' . $this->path);
}
$convertor = new PDFConvertor($this->storage, $this->path);
$convertor->execute();
}
protected function convertToPDF()
@ -51,9 +47,9 @@ class DocxAndOdtConvertor extends AbstractConvertor
*
* @throws \Exception
*/
public function convertToPdfWithLibreOffice()
public function convertToHTMLWithLibreOffice()
{
$this->convertToFormat('pdf');
$this->convertToFormat('html');
}
/**

6
app/Jobs/IngestDocuments.php

@ -83,8 +83,8 @@ class IngestDocuments implements ShouldQueue
protected function execute()
{
if ($this->fileResultType === 'json') {
$this->convertToJSON();
if ($this->fileResultType === 'html') {
$this->convert();
}
return;
}
@ -94,7 +94,7 @@ class IngestDocuments implements ShouldQueue
*
* @throws \Exception
*/
protected function convertToJSON()
protected function convert()
{
$convertor = new Convertor($this->path, $this->type);

20
app/Jobs/SendToCore.php

@ -124,11 +124,11 @@ class SendToCore implements ShouldQueue
protected function getContent()
{
$extension = $this->fileResultType === 'md' ? 'md' : 'json';
$extension = $this->fileResultType === 'html' ? 'html' : [];
$filePath = "$this->directoryPath/document.$extension";
$document = $this->storage->get($filePath);
$document = $this->encodeContent($document);
// $document = $this->encodeContent($document);
$images = [];
@ -154,14 +154,14 @@ class SendToCore implements ShouldQueue
];
}
protected function encodeContent($content)
{
$encoding = mb_detect_encoding($content, 'UTF-8, ISO-8859-1, WINDOWS-1252, WINDOWS-1251', true);
// protected function encodeContent($content)
// {
// $encoding = mb_detect_encoding($content, 'UTF-8, ISO-8859-1, WINDOWS-1252, WINDOWS-1251', true);
if ($encoding != 'UTF-8') {
$content = iconv($encoding, 'UTF-8//IGNORE', $content);
}
// if ($encoding != 'UTF-8') {
// $content = iconv($encoding, 'UTF-8//IGNORE', $content);
// }
return $content;
}
// return $content;
// }
}
Loading…
Cancel
Save