From 50ab7a6333566fc8ce8fc2ba0e66abe769d21617 Mon Sep 17 00:00:00 2001 From: Alex Puiu <=> Date: Wed, 20 Apr 2022 17:27:04 +0300 Subject: [PATCH] Send document back to core in HTML format --- app/Http/Controllers/IngestController.php | 2 +- app/Ingest/DocxAndOdtConvertor.php | 12 ++++-------- app/Jobs/IngestDocuments.php | 6 +++--- app/Jobs/SendToCore.php | 20 ++++++++++---------- 4 files changed, 18 insertions(+), 22 deletions(-) diff --git a/app/Http/Controllers/IngestController.php b/app/Http/Controllers/IngestController.php index 08fa795..9b0f970 100644 --- a/app/Http/Controllers/IngestController.php +++ b/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', ]); diff --git a/app/Ingest/DocxAndOdtConvertor.php b/app/Ingest/DocxAndOdtConvertor.php index 5b55d86..14ac711 100644 --- a/app/Ingest/DocxAndOdtConvertor.php +++ b/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'); } /** diff --git a/app/Jobs/IngestDocuments.php b/app/Jobs/IngestDocuments.php index f0a9ac0..3c5bd87 100644 --- a/app/Jobs/IngestDocuments.php +++ b/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); diff --git a/app/Jobs/SendToCore.php b/app/Jobs/SendToCore.php index 05d350d..4fa6f71 100644 --- a/app/Jobs/SendToCore.php +++ b/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; + // } }