]> _ Git - fluidbook-toolbox.git/commitdiff
wip #6598 @3
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 27 Dec 2023 11:09:14 +0000 (12:09 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 27 Dec 2023 11:09:14 +0000 (12:09 +0100)
.docker/dev/docker-compose.yml
.docker/syncprodtodev.exclude
app/Fluidbook/Farm.php
app/Models/FluidbookDocument.php
app/Models/FluidbookPublication.php
bin/startup.sh
scripts/update.sh

index f2fc02e5ec198dbc3838c0b3084648bfb20a5482..fea626a9e6b30290bbb2ea70a01f011a516d37cd 100644 (file)
@@ -178,6 +178,9 @@ volumes:
     driver_opts:
       sshcmd: "fluidbook@kingkong.cubedesigners.com:/home/fluidbook/data"
       allow_other: ""
+      cache: "no"
+      uid: 1001
+      gid: 33
       password: "Qu2E9uq48bBzsqGiZA"
 
   docs:
@@ -185,4 +188,7 @@ volumes:
     driver_opts:
       sshcmd: "fluidbook@dracula.cubedesigners.com:/data/fluidbook/docs"
       allow_other: ""
+      cache: "no"
+      uid: 1001
+      gid: 33
       password: "Qu2E9uq48bBzsqGiZA"
index 21e2359e380305be9a42d5e14b86c007d3c7012c..dd6248a04938dbeef102f1725879c9b7622bd24c 100644 (file)
@@ -3,6 +3,7 @@ fluidbookpublication/final
 fluidbookpublication/seo
 fluidbookpublication/pdf
 fluidbookcollection/final
+fluidbookcollection/download
 collection/final
 elearningpackage/final
 elearningmedia/final
@@ -13,3 +14,4 @@ app/public/elearningpackage
 app/public/fluidbookcollection
 app/public/quiz
 protected/youtube
+
index 66bbb881a5d52b4a2e8862e58e4f469f4c22cf0b..ee04f0b8388785bc6ff7d6097ef17c816f878041 100644 (file)
@@ -2,6 +2,7 @@
 
 namespace App\Fluidbook;
 
+use Cubist\PDF\PDFTools;
 use Cubist\Util\Files\Files;
 use Fluidbook\Tools\Jobs\ProcessFile;
 use hollodotme\FastCGI\Client;
@@ -14,9 +15,9 @@ use Mockery\Exception;
 class Farm
 {
     protected static $_outPDF = [];
-    protected static $_forceServer = false;
+    //protected static $_forceServer = false;
 
-    //protected static $_forceServer = 'alphaville';
+    protected static $_forceServer = 'alphaville';
 
     protected static $_region = Region::EUROPE;
 
@@ -114,7 +115,8 @@ class Farm
 
     public static function getFile($page, $format, $resolution, $quality, $withText, $withGraphics, $version, $resolutionRatio, $mobileFirstRatio, $path, $force = false)
     {
-        $params = ['toolbox' => 1,
+        $params = [
+            'operation' => 'documentfile',
             'page' => $page,
             'format' => $format,
             'resolution' => $resolution,
@@ -144,7 +146,9 @@ class Farm
             $out = self::_getOutDirFromPDF($pdf);
         }
 
-        $attrs = ['pdf' => $pdf,
+        $attrs = [
+            'operation' => 'pdffile',
+            'pdf' => $pdf,
             'page' => $page,
             'format' => $format,
             'resolution' => $resolution,
@@ -156,7 +160,7 @@ class Farm
 
         $cachekey = 'filefrompdf_' . hash('sha256', print_r($attrs, true));
 
-        $params = array_merge($attrs, ['toolbox' => 1,
+        $params = array_merge($attrs, [
             'force' => $force,
         ]);
 
@@ -184,30 +188,95 @@ class Farm
         return $res;
     }
 
+    public static function fixPDF($pdf, $out)
+    {
+        return self::_getFile(['operation' => 'fixpdf',
+            'pdf' => $pdf,
+            'out' => $out], 0,false);
+    }
+
+    public static function cutPDF($pdf, $mode, $out)
+    {
+        return self::_getFile(['operation' => 'cutpdf',
+            'pdf' => $pdf,
+            'out' => $out,
+            'mode' => $mode,
+        ], 0,false);
+    }
+
+    public static function trimPDF($pdf, $out)
+    {
+        return self::_getFile(['operation' => 'trimpdf',
+            'pdf' => $pdf,
+            'out' => $out,
+        ], 0,false);
+    }
+
+    public static function splitPDF($pdf, $out)
+    {
+        return self::_getFile(['operation' => 'splitpdf',
+            'pdf' => $pdf,
+            'out' => $out], 0,false);
+    }
+
+    public static function extractLinks($pdf, $out)
+    {
+        return self::_getFile(['operation' => 'extractlinks',
+            'pdf' => $pdf,
+            'out' => $out], 0,false);
+    }
+
+    public static function extractTexts($pdf, $out, $mode, $extractionMethod, $ignoreSeparators)
+    {
+        return self::_getFile(
+            ['operation' => 'extracttexts',
+                'pdf' => $pdf,
+                'out' => $out,
+                'mode' => $mode,
+                'method' => $extractionMethod,
+                'ignoreseparators' => $ignoreSeparators], 0,false);
+    }
+
+    public static function extractHighlightsData($pdf, $out, $mode, $ignoreSeparators)
+    {
+        return self::_getFile(
+            ['operation' => 'extracthightlightsdata',
+                'pdf' => $pdf,
+                'out' => $out,
+                'mode' => $mode,
+                'ignoreseparators' => $ignoreSeparators], 0,false);
+    }
+
     /**
      * @throws \Exception
      */
-    protected static function _getFile($params, $attempts = 3)
+    protected static function _getFile($params, $attempts = 3, $checkOutput = true)
     {
         $start = microtime(true);
         $farmer = self::pickOneServer();
 
+        $params['toolbox'] = '1';
+
         try {
             $output = self::sendRequest($farmer, 'process.php', $params);
         } catch (\Exception $e) {
             Log::error('Farm server error ' . $farmer['name'] . ' : ' . json_encode($params) . ' : ' . $e->getMessage());
             if ($attempts > 0) {
-                return static::_getFile($params, $attempts - 1);
+                return static::_getFile($params, $attempts - 1, $checkOutput);
             }
             return false;
         }
 
-        $output = trim($output);
+        if ($checkOutput) {
+            $output = trim($output);
 
-        if (file_exists($output)) {
-            $res = $output;
+            if (file_exists($output)) {
+                $res = $output;
+            } else {
+                $res = false;
+            }
         } else {
-            $res = false;
+            $res = true;
         }
 
         $time = round(microtime(true) - $start, 4);
@@ -216,7 +285,7 @@ class Farm
         if (!$res) {
             if ($attempts > 0) {
                 Log::warning('Farm failure (' . $farmer['name'] . ') : ' . $output . ' // ' . $log);
-                return static::_getFile($params, $attempts - 1);
+                return static::_getFile($params, $attempts - 1, $checkOutput);
             }
             throw new \Exception('Farm failure  (' . $farmer['name'] . ')  : ' . $output . ' // ' . $log);
         }
index c95e2bbdc3e66fcc3b806b4ed712350de72fbfbf..56751891f72fc474ce6e4aa2a8d19866bd9ac696 100644 (file)
@@ -137,13 +137,13 @@ class FluidbookDocument extends ToolboxModel
 
     public function extractTexts()
     {
-        PDFTools::extractTexts($this->getPDFSource(), $this->path(), 'standard', 'fluidbook', '');
-        PDFTools::extractHighlightsData($this->getPDFSource(), $this->path(), 'standard');
+        Farm::extractTexts($this->getPDFSource(), $this->path(), 'standard', 'fluidbook', '');
+        Farm::extractHighlightsData($this->getPDFSource(), $this->path(), 'standard', 'standard');
     }
 
     public function extractLinks()
     {
-        PDFTools::extractLinks($this->getPDFSource(), $this->path());
+        Farm::extractLinks($this->getPDFSource(), $this->path());
     }
 
     protected function _checkJobs($uploadID, $jobs, $nbfiles)
@@ -191,17 +191,17 @@ class FluidbookDocument extends ToolboxModel
 
     public function fixPDF()
     {
-        $fixed = $this->getPDFSource('fixed',false);
+        $fixed = $this->getPDFSource('fixed');
         $original = $this->getPDFSource('original');
         if (!file_exists($fixed) || filesize($fixed) === 0 || filemtime($fixed) < filemtime($original)) {
-            PDFTools::fixPDF($original, $fixed);
+            Farm::fixPDF($original, $fixed);
         }
         return $fixed;
     }
 
     public function splitPDF()
     {
-        PDFTools::split($this->getPDFSource(), $this->path('pdf'));
+        Farm::splitPDF($this->getPDFSource(), $this->path('pdf'));
     }
 
     /**
@@ -395,7 +395,10 @@ class FluidbookDocument extends ToolboxModel
     {
         $path = $this->_getTextPath($page, $type, $mode, $extractionMethod, $ignoreSeparators);
         if (!$this->_checkTextFile($path)) {
-            PDFTools::extractTexts($this->getPDFSource(), $this->path(), $mode, $extractionMethod, $ignoreSeparators);
+            Farm::extractTexts($this->getPDFSource(), $this->path(), $mode, $extractionMethod, $ignoreSeparators);
+            if (!Gzip::file_exists($path)) {
+                throw new \Exception('An error occured while producing file ' . $path);
+            }
         }
         return Gzip::path($path);
     }
@@ -409,7 +412,7 @@ class FluidbookDocument extends ToolboxModel
     {
         $path = $this->_getHightlightFilePath($page, $mode, $ignoreSeparators);
         if (!$this->_checkTextFile($path)) {
-            PDFTools::extractHighlightsData($this->getPDFSource(), $this->path(), $mode, $ignoreSeparators);
+            Farm::extractHighlightsData($this->getPDFSource(), $this->path(), $mode, $ignoreSeparators);
             if (!Gzip::file_exists($path)) {
                 throw new \Exception('An error occured while producing file ' . $path);
             }
@@ -424,68 +427,48 @@ class FluidbookDocument extends ToolboxModel
     }
 
     public function _getHightlightFilePath($page, $mode = 'standard', $ignoreSeparators = '')
+    {
+        return $this->_getTextBasePath($mode, $ignoreSeparators) . 'p' . $page . '.fby';
+    }
+
+    public function _getTextBasePath($mode = 'standard', $ignoreSeparators = '')
     {
         $sepFolder = '';
         if ($ignoreSeparators) {
             $sepFolder = 'sep_' . md5($ignoreSeparators) . '/';
         }
         $dir = $mode !== 'standard' ? $mode . '/' : '';
-        return $this->path('texts/' . $dir . $sepFolder) . 'p' . $page . '.fby';
+        return $this->path('texts/' . $dir . $sepFolder);
     }
 
     public function _getTextPath($page, $type = self::TEXT_PLAIN, $mode = 'standard', $extractionMethod = 'fluidbook', $ignoreSeparators = '')
     {
-        $sepFolder = '';
-        if ($ignoreSeparators) {
-            $sepFolder = 'sep_' . md5($ignoreSeparators) . '/';
-        }
-
         if ($mode === 'robust') {
             $extractionMethod = 'fluidbook';
         }
 
         $prefix = self::_getTextFilePrefix($extractionMethod);
-        $dir = $mode !== 'standard' ? $mode . '/' : '';
-        return $this->path('texts/' . $dir . $sepFolder) . $prefix . $type . $page . '.txt';
+        return $this->_getTextBasePath($mode, $ignoreSeparators) . $prefix . $type . $page . '.txt';
     }
 
-    public function getPDFSource($type = 'crop', $checkIfExists = true): string
+    public function getPDFSource($type = 'crop'): string
     {
-        $res = $this->path() . $type . '.pdf';
-        if ($checkIfExists && !file_exists($res)) {
-            if ($type === 'original') {
-                throw new \Exception('Missing original PDF file ' . $res);
-            } else if ($type === 'fixed') {
-                $this->fixPDF();
-            } else if ($type === 'crop') {
-                $this->cropAndCut();
-            }
-        }
-        return $res;
+        return $this->path() . $type . '.pdf';
     }
 
     public function cutDocument($mode)
     {
-        $fwstk = new FWSTK();
-        $fwstk->setArg('--input ' . $this->getPDFSource('fixed'));
-        $fwstk->setArg('--cut ' . $mode);
-        $fwstk->setArg('--output ' . $this->getPDFSource('crop', false));
-        $fwstk->execute();
+        Farm::cutPDF($this->getPDFSource('fixed'), $mode, $this->getPDFSource());
     }
 
     public function trimDocument()
     {
-
-        $fwstk = new FWSTK();
-        $fwstk->setArg('--input ' . $this->getPDFSource('fixed'));
-        $fwstk->setArg('--trim');
-        $fwstk->setArg('--output ' . $this->getPDFSource('crop', false));
-        $fwstk->execute();
+        Farm::trimPDF($this->getPDFSource('fixed'), $this->getPDFSource());
     }
 
     public function lnCrop()
     {
-        link($this->getPDFSource('fixed'), $this->getPDFSource('crop', false));
+        link($this->getPDFSource('fixed'), $this->getPDFSource());
     }
 
     protected function isCropped()
@@ -498,7 +481,7 @@ class FluidbookDocument extends ToolboxModel
         $infos = $this->_getInfos('fixed');
 
         $this->detectSpreads($infos);
-        $this->detectPageDifferences($infos);
+        //$this->detectPageDifferences($infos);
 
         if (!$this->isCropped()) {
             $this->lnCrop();
index 18ecc9f5dae2781b9ee0b1f7acc54407e668cb8f..52b41b7c956d28a1e547a9ad3dae8803887662b6 100644 (file)
@@ -38,7 +38,6 @@ use App\Jobs\FluidbookImagesPreprocess;
 use App\Jobs\FluidbookSocialImage;
 use App\Jobs\GenerateDeliveryThumbnailsPreview;
 use App\Models\Base\ToolboxDownloadable;
-use App\Models\Base\ToolboxSettingsModel;
 use App\Models\Base\ToolboxStatusModel;
 use App\Models\Traits\CheckHash;
 use App\Models\Traits\PublicationSettings;
@@ -604,11 +603,11 @@ class FluidbookPublication extends ToolboxStatusModel
         return $this->composition_updated_at->getTimestamp();
     }
 
-    public function getPDFSource($page, $type = 'crop', $checkIfExist = true): string
+    public function getPDFSource($page, $type = 'crop'): string
     {
         $compo = $this->getComposition()[$page];
         if ($type == 'crop') {
-            return self::_getDocument($compo[0])->getPDFSource($type, $checkIfExist);
+            return self::_getDocument($compo[0])->getPDFSource($type);
         }
     }
 
index 0c28109a93e7c1123a1b296ef267f0b5737034ff..9dddf8bfdb16670022a82b846704ced7874750fe 100644 (file)
@@ -66,7 +66,7 @@ if mountpoint -q "/application/protected/fluidbookpublication/docs"; then
     :
 else
     #sshfs -o reconnect,ServerAliveInterval=15,ServerAliveCountMax=3 -o cache=no -o sshfs_sync -o uid=1002 -o gid=33 -o allow_other root@godzilla.cubedesigners.com:/data/fluidbook/docs /application/protected/fluidbookpublication/docs
-    sshfs -o reconnect,ServerAliveInterval=15,ServerAliveCountMax=3 -o cache=no -o sshfs_sync -o uid=1002 -o gid=33 -o allow_other root@dracula.cubedesigners.com:/data/fluidbook/docs /application/protected/fluidbookpublication/docs
+    sshfs -o reconnect,ServerAliveInterval=15,ServerAliveCountMax=3 -o cache=no -o uid=1002 -o gid=33 -o allow_other root@dracula.cubedesigners.com:/data/fluidbook/docs /application/protected/fluidbookpublication/docs
 fi
 
 # Launch PHP
index 980b824b588af79b6c7988c0842de9e2e56da746..a57eb9b8b1e41873df2f4ea120ec383af8050024 100644 (file)
@@ -17,7 +17,7 @@ sudo /application/scripts/restartworkers.sh
 /application/scripts/updatenpm.sh
 sudo chown -R 1001:33 /application/storage/framework
 sudo chown -R 1001:33 /application/storage/framework
-php artisan optimize:clear
+#php artisan optimize:clear
 php artisan cubist:magic:precache
 php artisan toolbox:precache
 sudo chown -R 1001:33 /application/storage/framework