]> _ Git - fluidbook-toolbox.git/commitdiff
wip #5524 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 22 Feb 2023 09:28:26 +0000 (10:28 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 22 Feb 2023 09:28:26 +0000 (10:28 +0100)
.docker/docker-compose.yml
app/Fluidbook/Farm.php
app/Http/Controllers/Admin/Operations/FluidbookPublication/EditOperation.php
app/Models/FluidbookDocument.php
app/Models/FluidbookPublication.php
resources/linkeditor/js/linkeditor.loader.js
resources/views/fluidbook_publication/link_editor.blade.php

index d69616acc9f1f625c44209d6d61e4c52b70dc2f4..1ffddc3308747e9487e9d9aaab3b02222c94e302 100644 (file)
@@ -16,6 +16,7 @@ services:
       - '/data/extranet/www/fluidbook/books/working/:/application/protected/fluidbookpublication/working/'
       - '/data/extranet/www/fluidbook/books/links/:/application/protected/fluidbookpublication/links/'
       - '/home/extranet/www/fluidbook/cache/unzip/:/application/storage/fluidbook/cache/unzip/'
+      - '/data/toolbox/protected/fluidbookpublication/cache/:/application/protected/fluidbookpublication/cache/'
       - '/home/extranet:/home/extranet'
       - '/data/extranet:/data/extranet'
       - '/mnt:/mnt'
@@ -79,7 +80,8 @@ services:
       - '/mnt/sshfs/godzilla/data/fluidbook/docs/:/application/protected/fluidbookpublication/docs/'
       - '/data/extranet/www/fluidbook/books/working/:/application/protected/fluidbookpublication/working/'
       - '/data/extranet/www/fluidbook/books/links/:/application/protected/fluidbookpublication/links/'
-      - '/data/extranet/www/fluidbook/cache/unzip/:/application/storage/fluidbook/cache/unzip/'
+      - '/home/extranet/www/fluidbook/cache/unzip/:/application/storage/fluidbook/cache/unzip/'
+      - '/data/toolbox/protected/fluidbookpublication/cache/:/application/protected/fluidbookpublication/cache/'
       - '/home/extranet:/home/extranet'
       - '/data/extranet:/data/extranet'
       - '/mnt:/mnt'
index b4f8085023cca70d9a13b31f9faf7e2e8906b24c..ed73d0cc48d818e832d63104214729cab4d7a71b 100644 (file)
@@ -9,6 +9,8 @@ use hollodotme\FastCGI\SocketConnections\NetworkSocket;
 
 class Farm
 {
+
+    protected static $_forceServer = false;
     protected static $_farmServers = [
         ['name' => 'alphaville', 'host' => 'fluidbook-processfarm', 'port' => 9000, 'weight' => 24, 'region' => 'UE'],
         ['name' => 'brazil', 'host' => 'brazil.cubedesigners.com', 'weight' => 2, 'region' => 'US'],
@@ -23,6 +25,11 @@ class Farm
         ['name' => 'kingkong', 'host' => 'kingkong.cubedesigners.com', 'weight' => 6, 'region' => 'US'],
     ];
 
+    public static function forceServer($server)
+    {
+        self::$_forceServer = $server;
+    }
+
     protected static function _pingCache()
     {
         return Files::mkdir(storage_path('fluidbookfarm')) . '/pings';
@@ -40,6 +47,14 @@ class Farm
 
     public static function pickOneServer()
     {
+        if (self::$_forceServer) {
+            foreach (self::$_farmServers as $farmServer) {
+                if ($farmServer['name'] === self::$_forceServer) {
+                    return $farmServer;
+                }
+            }
+        }
+
         $hat = [];
         $pingCache = self::_pingCache();
         if (!file_exists($pingCache)) {
@@ -58,6 +73,7 @@ class Farm
         shuffle($hat);
         $i = array_pop($hat);
         return self::$_farmServers[$i];
+
     }
 
     public static function getFCGIConnexion(array $farm, $timeout = 240): NetworkSocket
@@ -75,12 +91,47 @@ class Farm
     }
 
     public static function getFile($page, $format, $resolution, $withText, $withGraphics, $version, $resolutionRatio, $mobileFirstRatio, $path, $force = false)
+    {
+        $params = ['toolbox' => 1,
+            'page' => $page,
+            'format' => $format,
+            'resolution' => $resolution,
+            'withText' => $withText,
+            'withGraphics' => $withGraphics,
+            'version' => $version,
+            'force' => $force,
+            'out' => $path,
+            'resolutionRatio' => $resolutionRatio,
+            'mobileRatio' => $mobileFirstRatio];
+        return self::_getFile($params);
+    }
+
+
+    public static function getFileFromPDF($pdf, $page, $format, $resolution, $withText = true, $withGraphics = true, $version = 'html', $out = null, $force = false)
+    {
+        if (null === $out) {
+            $hash = Files::hashFileAttributes($pdf);
+            $out = Files::mkdir(protected_path('fluidbookpublication/cache/pdffiles/' . $hash));
+        }
+        $params = ['toolbox' => 1,
+            'pdf' => $pdf,
+            'page' => $page,
+            'format' => $format,
+            'resolution' => $resolution,
+            'withText' => $withText,
+            'withGraphics' => $withGraphics,
+            'version' => $version,
+            'force' => $force,
+            'out' => $out];
+
+        return self::_getFile($params);
+    }
+
+    protected static function _getFile($params)
     {
         $start = microtime(true);
         $farmer = self::pickOneServer();
 
-        $params = ['toolbox' => 1, 'page' => $page, 'format' => $format, 'resolution' => $resolution, 'withText' => $withText, 'withGraphics' => $withGraphics, 'version' => $version, 'force' => $force, 'out' => $path, 'resolutionRatio' => $resolutionRatio, 'mobileRatio' => $mobileFirstRatio];
-
         $output = trim(self::sendRequest($farmer, 'process.php', $params));
 
         if (file_exists($output)) {
@@ -90,13 +141,14 @@ class Farm
         }
 
         $time = round(microtime(true) - $start, 4);
-        $log = '[' . $farmer['name'] . ']' . "\t" . date('Y-m-d H:i:s') . "\t" . $time . "\t$page|$format|$resolution|$withText|$withGraphics|$version\t($res)\t>>" . $output . "\n";
+        $log = '[' . $farmer['name'] . ']' . "\t" . date('Y-m-d H:i:s') . "\t" . $time . "\t" . implode('|', $params) . "\t($res)\t>>" . $output . "\n";
 
         error_log($log);
 
         return $res;
     }
 
+
     public static function ping($echo = true, $force = false)
     {
         $cache = self::_pingCache();
index ace3aa60e532e75ba68b2bb7c48f35d1a9728160..3b205c5e2c2f5da7dd011fc6ae802bef5f1ca106 100644 (file)
@@ -2,6 +2,7 @@
 
 namespace App\Http\Controllers\Admin\Operations\FluidbookPublication;
 
+use App\Fluidbook\Farm;
 use App\Fluidbook\Links;
 use App\Models\FluidbookPublication;
 use Cubist\Backpack\Http\Controllers\Base\XSendFileController;
@@ -136,7 +137,12 @@ trait EditOperation
         }
         /** @var FluidbookPublication $fluibdook */
         $fluibdook = FluidbookPublication::find($fluidbook_id);
+        $f = 'getFile';
         switch ($type) {
+            case 'thumbspdf':
+                $withGraphics = $withText = true;
+                $f = 'getThumbFile';
+                break;
             case 'raster':
             case 'vector':
                 $withText = $withGraphics = true;
@@ -151,7 +157,7 @@ trait EditOperation
                 $withGraphics = false;
                 break;
         }
-        $path = $fluibdook->getFile($page, $format, 150, $withText, $withGraphics);
+        $path = $fluibdook->$f($page, $format, 150, $withText, $withGraphics, 'html');
         return XSendFileController::sendfile($path);
     }
 
index a5a664b6b7d2f7c6d43bf838efb531110e8f12c2..388ad46d9defc84b0b62caf579df7cebd082bed9 100644 (file)
@@ -58,6 +58,12 @@ class FluidbookDocument extends ToolboxModel
         return sqrt($a4surface / $docSurface);
     }
 
+    public function getMobileFirstRatio()
+    {
+        $this->checkInfos();
+        return 620 / $this->pdf_data['size'][0];
+    }
+
     public function getPageSize($page)
     {
         return $this->pdf_data['page'][$page]['size'];
@@ -152,11 +158,7 @@ class FluidbookDocument extends ToolboxModel
         return $progress;
     }
 
-    public function getMobileFirstRatio()
-    {
-        $this->checkInfos();
-        return 620 / $this->pdf_data['size'][0];
-    }
+
 
     public function checkInfos($force = false)
     {
index 6c64f472c03fe278b661291f0e63d2f68c2cd86f..157baf6f8f63351c0477ef2256904e9c49470c1f 100644 (file)
@@ -8,6 +8,7 @@ use App\Fields\FluidbookChapters;
 use App\Fields\FluidbookComposition;
 use App\Fields\FluidbookLocale;
 use App\Fields\User;
+use App\Fluidbook\Farm;
 use App\Fluidbook\Links;
 use App\Http\Controllers\Admin\Operations\FluidbookPublication\CompositionOperation;
 use App\Http\Controllers\Admin\Operations\FluidbookPublication\DeletefbOperation;
@@ -253,8 +254,20 @@ class FluidbookPublication extends ToolboxSettingsModel
             $resolution .= '-' . $q;
         }
         $compo = $this->composition[$page];
-        $res = self::_getDocument($compo[0])->getFile($compo[1], $format, $resolution, $withText, $withGraphics, $version, $force);
-        return $res;
+        return self::_getDocument($compo[0])->getFile($compo[1], $format, $resolution, $withText, $withGraphics, $version, $force);
+    }
+
+
+    public function getThumbFile($page, $format, $resolution = 'thumb', $withText = true, $withGraphics = true, $version = '', $force = false)
+    {
+        if ($this->pdfThumbnails) {
+            $thumbpdf = $this->getAssetDir() . $this->pdfThumbnails;
+            if (file_exists($thumbpdf)) {
+                return Farm::getFileFromPDF($thumbpdf, $page, $format, $resolution, $withText, $withGraphics, $version, null, $force);
+            }
+        }
+        return $this->getFile($page, $format, $resolution, $withText, $withGraphics, $version, $force);
+
     }
 
     public function addWidgets()
index d2612012b979d04aa4ef9938fd32f0b22258b938..b64cb9dccc02cccc7568514e8d4dd0da3d50ab65 100644 (file)
@@ -80,7 +80,7 @@ LinkeditorLoader.prototype = {
                     c += '<img draggable="false" class="texts" src="texts_' + p + '.svg" />';
                 }
             }else if(this.pagesSource==='thumbnails'){
-                c += '<img draggable="false" src="thumb_' + p + '.' + imageFormat + '" />';
+                c += '<img draggable="false" src="thumbspdf_' + p + '.' + imageFormat + '" />';
             }
         }
         c += '</div>';
index 355017bd313ba9d917ed6947272eda2f3ed3e3e6..583ae3ed072ef5abd70556decf7146856b7c0266 100644 (file)
                         @endif
                     @endif
                     <div class="separator"></div>
-                    @if($fluidbook->pdfThumbnails)toggleThumbnailsPDF
+                    @if($fluidbook->pdfThumbnails)
                         <a href="#" data-action="" data-icon="pdf-thumbnails"
                            data-tooltip="{{__('Afficher les pages du PDF des miniatures')}}"></a>
                     @endif