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;
$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)) {
}
return $res;
-
}
protected function _sortLinksByTabOrder($a, $b)
$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 '';
}
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);
}
}
});
}
+ 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
*/
}
}
-
$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')) {
--- /dev/null
+<?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();
+ }
+}
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Log;
-class FluidbookDocumentFileProcess extends Base
+class FluidbookDocumentFileProcess extends BaseStatus
{
/** @var FluidbookDocument */
protected $document;
$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;
}
/**
$this->getFile($page, $settings->imageFormat, 'thumb');
}
+ $this->book->getLinksAndRulers($links, $rulers);
+
+
while (true) {
if ($this->_checkJobs()) {
return;
--- /dev/null
+<?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 ?? '');
+ }
+}