]> _ Git - fluidbook-toolbox.git/commitdiff
#7898 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 15 Jan 2026 16:27:50 +0000 (17:27 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 15 Jan 2026 16:27:50 +0000 (17:27 +0100)
app/Fluidbook/Compiler/Links.php
app/Fluidbook/Farm.php
app/Jobs/BaseStatus.php [new file with mode: 0644]
app/Jobs/FluidbookDocumentFileProcess.php
app/Jobs/FluidbookImagesPreprocess.php
app/Jobs/OCR.php [new file with mode: 0644]

index 6b676b9df233c028561487d1fe81d017610cda7e..5d52c5b9fb1eb804fa2128c18d0b495320924300 100644 (file)
@@ -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);
     }
 
 }
index 5c3e5c81132fc385162c7f45a5bde4f1d59d822c..1b828e695da3f00659cde4526900f99dbb580f17 100644 (file)
@@ -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 (file)
index 0000000..25f05fa
--- /dev/null
@@ -0,0 +1,27 @@
+<?php
+
+namespace App\Jobs;
+
+use Illuminate\Support\Facades\Cache;
+
+abstract class BaseStatus extends Base
+{
+
+    abstract protected function _cacheKey(): string;
+
+    public function setFinish($finish = true)
+    {
+        Cache::put($this->_cacheKey(), $finish, 1200);
+    }
+
+
+    public function isFinish()
+    {
+        return Cache::get($this->_cacheKey(), false);
+    }
+
+    public function isDone()
+    {
+        return $this->isFinish();
+    }
+}
index be4f78a0223b13244c56bf18e057c893042621f9..79abfb8991174ac92604a8382e74463a616f1b44 100644 (file)
@@ -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;
     }
 
     /**
index a8f078b18578749a5d375aeb6f8d4e8944c22292..381d5bfeab060c8fa598d60be600c2429b41cd75 100644 (file)
@@ -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 (file)
index 0000000..e886c08
--- /dev/null
@@ -0,0 +1,28 @@
+<?php
+
+namespace App\Jobs;
+
+use App\Fluidbook\Farm;
+
+class OCR extends BaseStatus
+{
+    public $file;
+    public $locale = null;
+
+    public function __construct($file, $locale = null)
+    {
+        $this->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 ?? '');
+    }
+}