From c8e2179111fc037bd39479b7ff6d1c5b77e9e8a4 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Mon, 5 Jun 2023 17:09:53 +0200 Subject: [PATCH] wip #5991 --- app/Fluidbook/Farm.php | 1 - app/Jobs/FluidbookDocumentFileProcess.php | 20 ++++++++++++++++---- app/Jobs/FluidbookImagesPreprocess.php | 10 ++++++++-- app/Models/FluidbookDocument.php | 8 ++------ app/Models/FluidbookPublication.php | 2 +- 5 files changed, 27 insertions(+), 14 deletions(-) diff --git a/app/Fluidbook/Farm.php b/app/Fluidbook/Farm.php index 0d21a49b3..ef9c820c8 100644 --- a/app/Fluidbook/Farm.php +++ b/app/Fluidbook/Farm.php @@ -127,7 +127,6 @@ class Farm 'version' => $version, 'out' => $out]; - $cachekey = 'filefrompdf_' . hash('sha256', print_r($attrs, true)); $params = array_merge($attrs, ['toolbox' => 1, diff --git a/app/Jobs/FluidbookDocumentFileProcess.php b/app/Jobs/FluidbookDocumentFileProcess.php index 75a2db1c7..6241d7484 100644 --- a/app/Jobs/FluidbookDocumentFileProcess.php +++ b/app/Jobs/FluidbookDocumentFileProcess.php @@ -20,25 +20,29 @@ class FluidbookDocumentFileProcess extends Base protected $finish = false; - public function __construct($document, $page, $format = 'jpg', $resolution = 150,$quality=85, $withText = true, $withGraphics = true, $version = 'html', $forceCheck = false, $forceProcess = false) + protected $path = ""; + + public function __construct($document, $page, $format = 'jpg', $resolution = 150, $quality = 85, $withText = true, $withGraphics = true, $version = 'html', $forceCheck = false, $forceProcess = false) { $this->onQueue('fluidbookprocess'); $this->document = $document; $this->page = $page; $this->format = $format; $this->resolution = $resolution; - $this->quality=$quality; + $this->quality = $quality; $this->withGraphics = $withGraphics; $this->withText = $withText; $this->version = $version; $this->forceCheck = $forceCheck || $forceProcess; $this->forceProcess = $forceProcess; + + $this->path = $this->document->_getPath($this->page, $this->format, $this->resolution, $this->quality, $this->withText, $this->withGraphics, $this->version); } public function handle() { $this->finish = false; - echo $this->document->getFile($this->page, $this->format, $this->resolution,$this->quality, $this->withText, $this->withGraphics, $this->version, $this->forceCheck, $this->forceProcess) . "\n"; + echo $this->document->getFile($this->page, $this->format, $this->resolution, $this->quality, $this->withText, $this->withGraphics, $this->version, $this->forceCheck, $this->forceProcess) . "\n"; $this->finish = true; } @@ -52,11 +56,19 @@ class FluidbookDocumentFileProcess extends Base public function isOK() { - return $this->document->hasFile($this->page, $this->format, $this->resolution,$this->quality, $this->withText, $this->withGraphics, $this->version, $this->forceCheck); + return $this->document->hasFile($this->page, $this->format, $this->resolution, $this->quality, $this->withText, $this->withGraphics, $this->version, $this->forceCheck); } public function isError() { return $this->finish && !$this->isOK(); } + + /** + * @return mixed|string + */ + public function getPath(): mixed + { + return $this->path; + } } diff --git a/app/Jobs/FluidbookImagesPreprocess.php b/app/Jobs/FluidbookImagesPreprocess.php index 8ffe401ab..a07f2d1b2 100644 --- a/app/Jobs/FluidbookImagesPreprocess.php +++ b/app/Jobs/FluidbookImagesPreprocess.php @@ -86,6 +86,9 @@ class FluidbookImagesPreprocess extends Base $done++; } } + if (rand(1, 10) === 5) { + echo $done . '/' . $nbjobs . "\n"; + } return $done === $nbjobs; } @@ -93,11 +96,14 @@ class FluidbookImagesPreprocess extends Base { $c = $this->book->composition[$page]; $doc = $this->book->getDocument($page); - $job = new FluidbookDocumentFileProcess($doc, $c[1], $format, $resolution, $withText, $withGraphics, $version); + $quality = $this->book->JPEGQuality ?: 85; + $job = new FluidbookDocumentFileProcess($doc, $c[1], $format, $resolution, $quality, $withText, $withGraphics, $version); + $this->jobs[] = $job; if ($job->isDone()) { return; } + echo $job->getPath() . "\n"; dispatch($job); - $this->jobs[] = $job; + } } diff --git a/app/Models/FluidbookDocument.php b/app/Models/FluidbookDocument.php index e78c9566e..f04ae8a5d 100644 --- a/app/Models/FluidbookDocument.php +++ b/app/Models/FluidbookDocument.php @@ -250,8 +250,6 @@ class FluidbookDocument extends ToolboxModel } if ($format === 'svg') { $version = 'html'; - } else if ($format === 'swf') { - $version = ''; } if ($resolution === 'thumb') { @@ -280,15 +278,13 @@ class FluidbookDocument extends ToolboxModel } $file .= '.svg'; } else if ($format === 'png' || $format === 'jpg') { - $q = ($format === 'jpg' && $quality !== 85) ? '-' . $quality : ''; + $q = ($format === 'jpg' && $quality != 85) ? '-' . $quality : ''; $prefix = $withText ? 't' : 'h'; if ($resolution === 'thumb') { $file = $dir . 'p' . $page . $q . '.' . $format; } else { $file = $dir . $prefix . $page . '-' . $resolution . $q . '.' . $format; } - } else if ($format === 'swf') { - $file = $dir . 'p' . $page . '.' . $format; } return $file; @@ -297,7 +293,7 @@ class FluidbookDocument extends ToolboxModel protected function fileCacheKey($page, $format = 'jpg', $resolution = 150, $quality = 85, $withText = true, $withGraphics = true, $version = 'html') { $this->_normalize($format, $resolution, $quality, $withText, $withGraphics, $version); - return 'FluidbookDocument_' . $this->id . '_' . $page . '_' . $format . '_' . $resolution . '_' . ($withText ? '1' : '0') . '_' . ($withGraphics ? '1' : '0') . '_' . $version; + return 'FluidbookDocument_' . $this->id . '_' . $page . '_' . $format . '_' . $resolution . '_' . $quality . '_' . ($withText ? '1' : '0') . '_' . ($withGraphics ? '1' : '0') . '_' . $version; } public function getFile($page, $format = 'jpg', $resolution = 150, $quality = 85, $withText = true, $withGraphics = true, $version = 'html', $forceCheck = false, $forceProcess = false) diff --git a/app/Models/FluidbookPublication.php b/app/Models/FluidbookPublication.php index e09f22219..c09bccca4 100644 --- a/app/Models/FluidbookPublication.php +++ b/app/Models/FluidbookPublication.php @@ -374,7 +374,7 @@ class FluidbookPublication extends ToolboxSettingsModel return Farm::getFileFromPDF($thumbpdf, $page, $format, $resolution, $this->JPEGQuality, $withText, $withGraphics, $version, null, $force); } } - return $this->getFile($page, $format, $resolution, $this->JPEGQuality, $withText, $withGraphics, $version, $force); + return $this->getFile($page, $format, $resolution, $withText, $withGraphics, $version, $force); } -- 2.39.5