From: Vincent Vanwaelscappel Date: Thu, 15 Jan 2026 16:27:50 +0000 (+0100) Subject: #7898 @1 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=dd03af8383c0f0dc53d1f28175a0a5829ecade6b;p=fluidbook-toolbox.git #7898 @1 --- diff --git a/app/Fluidbook/Compiler/Links.php b/app/Fluidbook/Compiler/Links.php index 6b676b9df..5d52c5b9f 100644 --- a/app/Fluidbook/Compiler/Links.php +++ b/app/Fluidbook/Compiler/Links.php @@ -2,8 +2,10 @@ namespace App\Fluidbook\Compiler; +use App\Fluidbook\Farm; use App\Fluidbook\Link\Link; use App\Fluidbook\Link\LinksData; +use App\Jobs\OCR; use App\SubForms\Link\Base; use Cubist\Util\CommandLine\Docling; use Cubist\Util\Graphics\Color; @@ -335,8 +337,6 @@ trait Links $linkData['page'] = 'background'; } - $extra = - $linkData['hidden'] = in_array($linkData['uid'], $hiddenLinks); $linkData['showHidden'] = $linkData['hidden'] && in_array($linkData['uid'], $showHiddenLinks); if (isset($linkData['zindex']) && $linkData['zindex'] < 50 && in_array($linkData['uid'], $closedLinks)) { @@ -519,7 +519,6 @@ trait Links } return $res; - } protected function _sortLinksByTabOrder($a, $b) @@ -532,8 +531,12 @@ trait Links $this->config->push('triggersLinks', ['page' => $page, 'link' => $link, 'delay' => $delay]); } - public function getLinkAlternativeText($link) + public function getLinkAlternativeText($link, $returnJob = false) { + if (!$link->getOCR()) { + return ''; + } + if (Url::isDistant($link->to)) { return ''; } @@ -542,8 +545,16 @@ trait Links if (!file_exists($file)) { return ''; } - $res = Docling::OCR($file, $this->getFluidbook()->locale); - return $res; + $ext = ['jpg', 'jpeg', 'png', 'svg', 'pdf']; + $f = new \SplFileInfo($file); + if (!in_array($f->getExtension(), $ext)) { + return ''; + } + + if ($returnJob) { + return new OCR($file, $this->getFluidbook()->locale); + } + return Farm::OCR($file, $this->getFluidbook()->locale); } } diff --git a/app/Fluidbook/Farm.php b/app/Fluidbook/Farm.php index 5c3e5c811..1b828e695 100644 --- a/app/Fluidbook/Farm.php +++ b/app/Fluidbook/Farm.php @@ -315,6 +315,16 @@ class Farm }); } + public static function OCR($file, $locale) + { + return static::lock($file, 'ocr_' . $locale, function () use ($file, $locale) { + return self::_getFile( + ['operation' => 'ocr', + 'file' => $file, + 'locale' => $locale], 0, true, true); + }); + } + /** * @throws \Exception */ @@ -354,11 +364,16 @@ class Farm } } - $time = round(microtime(true) - $start, 4); $log = '[' . $farmer['name'] . ']' . "\t" . date('Y-m-d H:i:s') . "\t" . $time . "\t" . self::serializeParams($params) . "\t($res)\t>>" . $output . "\n"; - $dir = isset($params['pdf']) ? dirname($params['pdf']) : $params['out']; + if(isset($params['pdf'])){ + $dir=dirname($params['pdf']) ; + }else if(isset($params['file'])){ + $dir=dirname($params['file']) ; + }else{ + $dir=$params['out']; + } $logfile = $dir . '/farm.log'; if ($fp = fopen($logfile, 'ab')) { diff --git a/app/Jobs/BaseStatus.php b/app/Jobs/BaseStatus.php new file mode 100644 index 000000000..25f05fa96 --- /dev/null +++ b/app/Jobs/BaseStatus.php @@ -0,0 +1,27 @@ +_cacheKey(), $finish, 1200); + } + + + public function isFinish() + { + return Cache::get($this->_cacheKey(), false); + } + + public function isDone() + { + return $this->isFinish(); + } +} diff --git a/app/Jobs/FluidbookDocumentFileProcess.php b/app/Jobs/FluidbookDocumentFileProcess.php index be4f78a02..79abfb899 100644 --- a/app/Jobs/FluidbookDocumentFileProcess.php +++ b/app/Jobs/FluidbookDocumentFileProcess.php @@ -6,7 +6,7 @@ use App\Models\FluidbookDocument; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Log; -class FluidbookDocumentFileProcess extends Base +class FluidbookDocumentFileProcess extends BaseStatus { /** @var FluidbookDocument */ protected $document; @@ -54,15 +54,10 @@ class FluidbookDocumentFileProcess extends Base $this->setFinish(); } - public function setFinish($finish = true) - { - Cache::put('job_' . $this->path, $finish, 1200); - } - - public function isFinish() + protected function _cacheKey(): string { - return Cache::get('job_' . $this->path, false); + return 'job_' . $this->path; } /** diff --git a/app/Jobs/FluidbookImagesPreprocess.php b/app/Jobs/FluidbookImagesPreprocess.php index a8f078b18..381d5bfea 100644 --- a/app/Jobs/FluidbookImagesPreprocess.php +++ b/app/Jobs/FluidbookImagesPreprocess.php @@ -80,6 +80,9 @@ class FluidbookImagesPreprocess extends Base $this->getFile($page, $settings->imageFormat, 'thumb'); } + $this->book->getLinksAndRulers($links, $rulers); + + while (true) { if ($this->_checkJobs()) { return; diff --git a/app/Jobs/OCR.php b/app/Jobs/OCR.php new file mode 100644 index 000000000..e886c0855 --- /dev/null +++ b/app/Jobs/OCR.php @@ -0,0 +1,28 @@ +file = $file; + $this->locale = $locale; + } + + public function handle() + { + Farm::OCR($this->file, $this->locale); + $this->setFinish(); + } + + protected function _cacheKey(): string + { + return 'job_ocr_' . $this->file . '_' . ($this->locale ?? ''); + } +}