]> _ Git - fluidbook-toolbox.git/commitdiff
wip #5991 @0.25
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 5 Jun 2023 12:20:27 +0000 (14:20 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 5 Jun 2023 12:20:27 +0000 (14:20 +0200)
app/Fluidbook/Compiler/Compiler.php
app/Fluidbook/Farm.php
app/Http/Controllers/Admin/Operations/Tools/PDF2SVGOperation.php
app/Jobs/FluidbookDocumentFileProcess.php
app/Models/FluidbookDocument.php
app/Models/FluidbookPublication.php
composer.lock

index 95265d73927d9f078b94836b3bd02636027d1fb8..36467d7f5c1525c1f45e82f8ec2baba1161764b1 100644 (file)
@@ -3111,4 +3111,9 @@ class Compiler extends Base implements CompilerInterface
     {
         return (int)$this->config->pages;
     }
+
+    public function getQuality(): int
+    {
+        return (int)$this->config->JPEGQuality;
+    }
 }
index 414f194df212639e43fd819a8b4b2f7b5f6a31d3..0d21a49b3bc403785bdb941ac213ee1de932cc48 100644 (file)
@@ -7,6 +7,7 @@ use hollodotme\FastCGI\Client;
 use hollodotme\FastCGI\Requests\PostRequest;
 use hollodotme\FastCGI\SocketConnections\NetworkSocket;
 use Illuminate\Support\Facades\Cache;
+use Illuminate\Support\Facades\Log;
 
 class Farm
 {
@@ -91,7 +92,7 @@ class Farm
         return trim($response->getBody());
     }
 
-    public static function getFile($page, $format, $resolution, $withText, $withGraphics, $version, $resolutionRatio, $mobileFirstRatio, $path, $force = false)
+    public static function getFile($page, $format, $resolution, $quality, $withText, $withGraphics, $version, $resolutionRatio, $mobileFirstRatio, $path, $force = false)
     {
         $params = ['toolbox' => 1,
             'page' => $page,
@@ -100,6 +101,7 @@ class Farm
             'withText' => $withText,
             'withGraphics' => $withGraphics,
             'version' => $version,
+            'quality' => $quality,
             'force' => $force,
             'out' => $path,
             'resolutionRatio' => $resolutionRatio,
@@ -108,7 +110,7 @@ class Farm
     }
 
 
-    public static function getFileFromPDF($pdf, $page, $format, $resolution, $withText = true, $withGraphics = true, $version = 'html', $out = null, $force = false)
+    public static function getFileFromPDF($pdf, $page, $format, $resolution, $quality, $withText = true, $withGraphics = true, $version = 'html', $out = null, $force = false)
     {
         if (null === $out) {
             $hash = Files::hashFileAttributes($pdf);
@@ -119,6 +121,7 @@ class Farm
             'page' => $page,
             'format' => $format,
             'resolution' => $resolution,
+            'quality' => $quality,
             'withText' => $withText,
             'withGraphics' => $withGraphics,
             'version' => $version,
@@ -145,7 +148,14 @@ class Farm
         $start = microtime(true);
         $farmer = self::pickOneServer();
 
-        $output = trim(self::sendRequest($farmer, 'process.php', $params));
+        try {
+            $output = self::sendRequest($farmer, 'process.php', $params);
+        } catch (\Exception $e) {
+            Log::error('Farm server error ' . $farmer['name'] . ' : ' . json_encode($params) . ' : ' . $e->getMessage());
+            exit;
+        }
+
+        $output = trim($output);
 
         if (file_exists($output)) {
             $res = $output;
index 423457e95d6f82861154f32e57e7934d04abd439..c23b54d0cf0e541a4a3af11bf1de348d145bf0b8 100644 (file)
@@ -30,7 +30,7 @@ trait PDF2SVGOperation
 
     public function pdf2svg()
     {
-        $form = new Form(backpack_url('tools/convertpdf'));
+        $form = new Form(backpack_url('opentools/convertpdf'));
         $form->setEnctype('multipart/form-data');
         $form->setTitle(__('Convertir un fichier pdf en images'));
         $form->setSubmitLabel(__('Convertir'));
index cff10bacb5f80ecd4be4d32a652addf92077d3b7..8f564bfc10162dfd4bcec3239d17d523509660c7 100644 (file)
@@ -19,13 +19,14 @@ class FluidbookDocumentFileProcess extends Base
 
     protected $finish = false;
 
-    public function __construct($document, $page, $format = 'jpg', $resolution = 150, $withText = true, $withGraphics = true, $version = 'html', $forceCheck = false, $forceProcess = false)
+    public function __construct($document, $page, $format = 'jpg', $resolution = 150,$quality=85, $withText = true, $withGraphics = true, $version = 'html', $forceCheck = false, $forceProcess = false)
     {
         $this->onQueue('fluidbookprocess');
         $this->document = $document;
         $this->page = $page;
         $this->format = $format;
         $this->resolution = $resolution;
+        $this->quality=$quality;
         $this->withGraphics = $withGraphics;
         $this->withText = $withText;
         $this->version = $version;
@@ -36,7 +37,7 @@ class FluidbookDocumentFileProcess extends Base
     public function handle()
     {
         $this->finish = false;
-        echo $this->document->getFile($this->page, $this->format, $this->resolution, $this->withText, $this->withGraphics, $this->version, $this->forceCheck, $this->forceProcess) . "\n";
+        echo $this->document->getFile($this->page, $this->format, $this->resolution,$this->quality, $this->withText, $this->withGraphics, $this->version, $this->forceCheck, $this->forceProcess) . "\n";
         $this->finish = true;
     }
 
@@ -50,7 +51,7 @@ class FluidbookDocumentFileProcess extends Base
 
     public function isOK()
     {
-        return $this->document->hasFile($this->page, $this->format, $this->resolution, $this->withText, $this->withGraphics, $this->version, $this->forceCheck);
+        return $this->document->hasFile($this->page, $this->format, $this->resolution,$this->quality, $this->withText, $this->withGraphics, $this->version, $this->forceCheck);
     }
 
     public function isError()
index cf0bd14623c9984b41efbc846d000d216901d7f7..daba021d72cdf713627c447b5d1c78b104fc2c9e 100644 (file)
@@ -209,14 +209,14 @@ class FluidbookDocument extends ToolboxModel
         return $res;
     }
 
-    public function hasFile($page, $format = 'jpg', $resolution = 150, $withText = true, $withGraphics = true, $version = 'html', $forceCheck = false)
+    public function hasFile($page, $format = 'jpg', $resolution = 150, $quality = 85, $withText = true, $withGraphics = true, $version = 'html', $forceCheck = false)
     {
-        $this->_normalize($format, $resolution, $withText, $withGraphics, $version);
-        $cacheKey = $this->fileCacheKey($page, $format, $resolution, $withText, $withGraphics, $version);
+        $this->_normalize($format, $resolution, $quality, $withText, $withGraphics, $version);
+        $cacheKey = $this->fileCacheKey($page, $format, $resolution, $quality, $withText, $withGraphics, $version);
         if (!$forceCheck && Cache::has($cacheKey)) {
             return true;
         } else {
-            $path = $this->_getPath($page, $format, $resolution, $withText, $withGraphics, $version);
+            $path = $this->_getPath($page, $format, $resolution, $quality, $withText, $withGraphics, $version);
             $minsize = $format === 'svg' ? 100 : 1;
 
             if (!file_exists($path)) {
@@ -243,7 +243,7 @@ class FluidbookDocument extends ToolboxModel
         }
     }
 
-    protected function _normalize(&$format, &$resolution, &$withText, &$withGraphics, &$version)
+    protected function _normalize(&$format, &$resolution, &$quality, &$withText, &$withGraphics, &$version)
     {
         if ($format === 'jpeg') {
             $format = 'jpg';
@@ -261,14 +261,14 @@ class FluidbookDocument extends ToolboxModel
         }
     }
 
-    public function _getPath($page, $format = 'jpg', $resolution = 150, $withText = true, $withGraphics = true, $version = 'html')
+    public function _getPath($page, $format = 'jpg', $resolution = 150, $quality = 85, $withText = true, $withGraphics = true, $version = 'html')
     {
-        $cacheKey = $this->fileCacheKey($page, $format, $resolution, $withText, $withGraphics, $version);
+        $cacheKey = $this->fileCacheKey($page, $format, $resolution, $quality, $withText, $withGraphics, $version);
         if (Cache::has($cacheKey)) {
             return Cache::get($cacheKey);
         }
 
-        $this->_normalize($format, $resolution, $withText, $withGraphics, $version);
+        $this->_normalize($format, $resolution, $quality, $withText, $withGraphics, $version);
 
         $dir = $this->path($version) . '/';
 
@@ -293,15 +293,15 @@ class FluidbookDocument extends ToolboxModel
         return $file;
     }
 
-    protected function fileCacheKey($page, $format = 'jpg', $resolution = 150, $withText = true, $withGraphics = true, $version = 'html')
+    protected function fileCacheKey($page, $format = 'jpg', $resolution = 150, $quality = 85, $withText = true, $withGraphics = true, $version = 'html')
     {
-        $this->_normalize($format, $resolution, $withText, $withGraphics, $version);
+        $this->_normalize($format, $resolution, $quality, $withText, $withGraphics, $version);
         return 'FluidbookDocument_' . $this->id . '_' . $page . '_' . $format . '_' . $resolution . '_' . ($withText ? '1' : '0') . '_' . ($withGraphics ? '1' : '0') . '_' . $version;
     }
 
-    public function getFile($page, $format = 'jpg', $resolution = 150, $withText = true, $withGraphics = true, $version = 'html', $forceCheck = false, $forceProcess = false)
+    public function getFile($page, $format = 'jpg', $resolution = 150, $quality = 85, $withText = true, $withGraphics = true, $version = 'html', $forceCheck = false, $forceProcess = false)
     {
-        $this->_normalize($format, $resolution, $withText, $withGraphics, $version);
+        $this->_normalize($format, $resolution, $quality, $withText, $withGraphics, $version);
         if ($forceProcess) {
             $this->removeFile($page, $format, $resolution, $withText, $withGraphics, $version);
         }
@@ -311,32 +311,32 @@ class FluidbookDocument extends ToolboxModel
         if ($forceCheck) {
             Cache::forget($cacheKey);
         }
-        $res = Cache::tags('fluidbook_document_' . $this->id)->rememberForever($cacheKey, function () use ($doc, $page, $format, $resolution, $withText, $withGraphics, $version) {
-            return $doc->_getFile($page, $format, $resolution, $withText, $withGraphics, $version);
+        $res = Cache::tags('fluidbook_document_' . $this->id)->rememberForever($cacheKey, function () use ($doc, $page, $format, $resolution, $quality, $withText, $withGraphics, $version) {
+            return $doc->_getFile($page, $format, $resolution, $quality, $withText, $withGraphics, $version);
         });
         if (!$res && !$forceProcess) {
-            return $this->getFile($page, $format, $resolution, $withText, $withGraphics, $version, true, true);
+            return $this->getFile($page, $format, $resolution, $quality, $withText, $withGraphics, $version, true, true);
         }
         return $res;
     }
 
-    public function removeFile($page, $format = 'jpg', $resolution = 150, $withText = true, $withGraphics = true, $version = 'html')
+    public function removeFile($page, $format = 'jpg', $resolution = 150, $quality = 85, $withText = true, $withGraphics = true, $version = 'html')
     {
-        $path = $this->_getPath($page, $format, $resolution, $withText, $withGraphics, $version);
+        $path = $this->_getPath($page, $format, $resolution, $quality, $withText, $withGraphics, $version);
         if (file_exists($path)) {
             unlink($path);
         }
-        Cache::forget($this->fileCacheKey($page, $format, $resolution, $withText, $withGraphics, $version));
+        Cache::forget($this->fileCacheKey($page, $format, $resolution, $quality, $withText, $withGraphics, $version));
     }
 
 
-    public function _getFile($page, $format = 'jpg', $resolution = 150, $withText = true, $withGraphics = true, $version = 'html', $forceCheck = true)
+    public function _getFile($page, $format = 'jpg', $resolution = 150, $quality = 85, $withText = true, $withGraphics = true, $version = 'html', $forceCheck = true)
     {
-        if (!$this->hasFile($page, $format, $resolution, $withText, $withGraphics, $version, $forceCheck)) {
-            return Farm::getFile($page, $format, $resolution, $withText, $withGraphics, $version, $this->getResolutionRatio(), $this->getMobileFirstRatio(), $this->path());
+        if (!$this->hasFile($page, $format, $resolution, $quality, $withText, $withGraphics, $version, $forceCheck)) {
+            return Farm::getFile($page, $format, $resolution, $quality, $withText, $withGraphics, $version, $this->getResolutionRatio(), $this->getMobileFirstRatio(), $this->path());
         }
 
-        $path = $this->_getPath($page, $format, $resolution, $withText, $withGraphics, $version);
+        $path = $this->_getPath($page, $format, $resolution, $quality, $withText, $withGraphics, $version);
         touch($path);
         return $path;
     }
index 2b83524c450c514afd815c0dbfa1460b296fdf8a..e09f22219f2ccbbfa375c826643046cf2aeac801 100644 (file)
@@ -361,16 +361,8 @@ class FluidbookPublication extends ToolboxSettingsModel
 
     public function getFile($page, $format = 'jpg', $resolution = 150, $withText = true, $withGraphics = true, $version = 'html', $force = false)
     {
-        if ($format === 'jpg') {
-            $q = $this->JPEGQuality ?? 85;
-        } else {
-            $q = 85;
-        }
-        if ($q != 85) {
-            $resolution .= '-' . $q;
-        }
         $compo = $this->composition[$page];
-        return self::_getDocument($compo[0])->getFile($compo[1], $format, $resolution, $withText, $withGraphics, $version, $force);
+        return self::_getDocument($compo[0])->getFile($compo[1], $format, $resolution, $this->JPEGQuality, $withText, $withGraphics, $version, $force);
     }
 
 
@@ -379,10 +371,10 @@ class FluidbookPublication extends ToolboxSettingsModel
         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 Farm::getFileFromPDF($thumbpdf, $page, $format, $resolution, $this->JPEGQuality, $withText, $withGraphics, $version, null, $force);
             }
         }
-        return $this->getFile($page, $format, $resolution, $withText, $withGraphics, $version, $force);
+        return $this->getFile($page, $format, $resolution, $this->JPEGQuality, $withText, $withGraphics, $version, $force);
 
     }
 
index af7a2888410824d5029c7aa16d081b73a8db7a00..fa639ec2fb06538051fc19ec8d794cd6c1211627 100644 (file)
@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "acbf857db884549552451fd0627e815a",
+    "content-hash": "fef46b5bfa05bbfea931657ffa20b91f",
     "packages": [
         {
             "name": "archtechx/enums",
             "source": {
                 "type": "git",
                 "url": "git://git.cubedesigners.com/cubist_pdf.git",
-                "reference": "ad6cfa74d75d16e6802520c9581d49fcfa4a9bf8"
+                "reference": "aa082e3acaca6bef981ae178938945af5e5eb2ca"
             },
             "dist": {
                 "type": "tar",
-                "url": "https://composer.cubedesigners.com/dist/cubist/pdf/cubist-pdf-dev-master-116e2d.tar",
-                "reference": "ad6cfa74d75d16e6802520c9581d49fcfa4a9bf8",
-                "shasum": "8373614077332bc998389e20c4f7ae0d5662f1e9"
+                "url": "https://composer.cubedesigners.com/dist/cubist/pdf/cubist-pdf-dev-master-ffceb2.tar",
+                "reference": "aa082e3acaca6bef981ae178938945af5e5eb2ca",
+                "shasum": "ab0ed6813ff314253079f48f9101395b42d32538"
             },
             "require": {
                 "cubist/util": "dev-master",
                 "cubist",
                 "pdf"
             ],
-            "time": "2023-04-06T09:19:37+00:00"
+            "time": "2023-06-05T10:42:49+00:00"
         },
         {
             "name": "cubist/scorm",
         },
         {
             "name": "doctrine/deprecations",
-            "version": "v1.1.0",
+            "version": "v1.1.1",
             "source": {
                 "type": "git",
                 "url": "https://github.com/doctrine/deprecations.git",
-                "reference": "8cffffb2218e01f3b370bf763e00e81697725259"
+                "reference": "612a3ee5ab0d5dd97b7cf3874a6efe24325efac3"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/doctrine/deprecations/zipball/8cffffb2218e01f3b370bf763e00e81697725259",
-                "reference": "8cffffb2218e01f3b370bf763e00e81697725259",
+                "url": "https://api.github.com/repos/doctrine/deprecations/zipball/612a3ee5ab0d5dd97b7cf3874a6efe24325efac3",
+                "reference": "612a3ee5ab0d5dd97b7cf3874a6efe24325efac3",
                 "shasum": ""
             },
             "require": {
-                "php": "^7.1|^8.0"
+                "php": "^7.1 || ^8.0"
             },
             "require-dev": {
                 "doctrine/coding-standard": "^9",
-                "phpunit/phpunit": "^7.5|^8.5|^9.5",
-                "psr/log": "^1|^2|^3"
+                "phpstan/phpstan": "1.4.10 || 1.10.15",
+                "phpstan/phpstan-phpunit": "^1.0",
+                "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5",
+                "psalm/plugin-phpunit": "0.18.4",
+                "psr/log": "^1 || ^2 || ^3",
+                "vimeo/psalm": "4.30.0 || 5.12.0"
             },
             "suggest": {
                 "psr/log": "Allows logging deprecations via PSR-3 logger implementation"
             "homepage": "https://www.doctrine-project.org/",
             "support": {
                 "issues": "https://github.com/doctrine/deprecations/issues",
-                "source": "https://github.com/doctrine/deprecations/tree/v1.1.0"
+                "source": "https://github.com/doctrine/deprecations/tree/v1.1.1"
             },
-            "time": "2023-05-29T18:55:17+00:00"
+            "time": "2023-06-03T09:27:29+00:00"
         },
         {
             "name": "doctrine/event-manager",
             "source": {
                 "type": "git",
                 "url": "git://git.cubedesigners.com/fluidbook_tools.git",
-                "reference": "62113b9880ca6515de74ca7161f6293b7feafa44"
+                "reference": "f370f46431a6c2d6bc88f765555ac4a2b1710cf7"
             },
             "dist": {
                 "type": "tar",
-                "url": "https://composer.cubedesigners.com/dist/fluidbook/tools/fluidbook-tools-dev-master-5738ef.tar",
-                "reference": "62113b9880ca6515de74ca7161f6293b7feafa44",
-                "shasum": "dc6651251450309fcace894ac9b06b9781d5f307"
+                "url": "https://composer.cubedesigners.com/dist/fluidbook/tools/fluidbook-tools-dev-master-d4e856.tar",
+                "reference": "f370f46431a6c2d6bc88f765555ac4a2b1710cf7",
+                "shasum": "91cfc88a62fa8b4d47063a2ec9aa9d382972be6a"
             },
             "require": {
                 "barryvdh/laravel-debugbar": "*",
                 }
             ],
             "description": "Fluidbook Tools",
-            "time": "2023-06-01T09:36:30+00:00"
+            "time": "2023-06-05T11:49:06+00:00"
         },
         {
             "name": "fruitcake/php-cors",
         },
         {
             "name": "mockery/mockery",
-            "version": "1.5.1",
+            "version": "1.6.0",
             "source": {
                 "type": "git",
                 "url": "https://github.com/mockery/mockery.git",
-                "reference": "e92dcc83d5a51851baf5f5591d32cb2b16e3684e"
+                "reference": "bac1765cb52bbd3364a870e920cb69cd859ee302"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/mockery/mockery/zipball/e92dcc83d5a51851baf5f5591d32cb2b16e3684e",
-                "reference": "e92dcc83d5a51851baf5f5591d32cb2b16e3684e",
+                "url": "https://api.github.com/repos/mockery/mockery/zipball/bac1765cb52bbd3364a870e920cb69cd859ee302",
+                "reference": "bac1765cb52bbd3364a870e920cb69cd859ee302",
                 "shasum": ""
             },
             "require": {
                 "phpunit/phpunit": "<8.0"
             },
             "require-dev": {
-                "phpunit/phpunit": "^8.5 || ^9.3"
+                "phpunit/phpunit": "^8.5 || ^9.3",
+                "psalm/plugin-phpunit": "^0.18",
+                "vimeo/psalm": "^5.9"
             },
             "type": "library",
             "extra": {
                 }
             },
             "autoload": {
-                "psr-0": {
-                    "Mockery": "library/"
+                "files": [
+                    "library/helpers.php",
+                    "library/Mockery.php"
+                ],
+                "psr-4": {
+                    "Mockery\\": "library/Mockery"
                 }
             },
             "notification-url": "https://packagist.org/downloads/",
             ],
             "support": {
                 "issues": "https://github.com/mockery/mockery/issues",
-                "source": "https://github.com/mockery/mockery/tree/1.5.1"
+                "source": "https://github.com/mockery/mockery/tree/1.6.0"
             },
-            "time": "2022-09-07T15:32:08+00:00"
+            "time": "2023-05-03T12:55:29+00:00"
         },
         {
             "name": "myclabs/deep-copy",