]> _ Git - fluidbook-toolbox.git/commitdiff
fix #6066 @0.75
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 18 Jul 2023 07:46:05 +0000 (09:46 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 18 Jul 2023 07:46:05 +0000 (09:46 +0200)
app/Console/Commands/FluidbookGeneratePreview.php
app/Http/Controllers/Admin/Operations/FluidbookPublication/DownloadOperation.php
app/Jobs/GenerateDeliveryThumbnailsPreview.php
app/Models/FluidbookPublication.php
resources/fluidbookpublication/delivery/preview.js [new file with mode: 0644]
resources/fluidbooktheme/theme_preview/secondpage_preview.js [deleted file]
resources/views/fluidbook_publication/delivery/index.blade.php

index 73a595e065b5a3dbac0bd06335f377f833fbd6c9..1f9ab63e4d22ec0e390d754bf775e012d7ec30a3 100644 (file)
@@ -14,7 +14,7 @@ class FluidbookGeneratePreview extends Command
      *
      * @var string
      */
-    protected $signature = 'fluidbook:preview-generate {id} {sync?}';
+    protected $signature = 'fluidbook:preview-generate {id} {--sync}';
 
     /**
      * The console command description.
@@ -30,22 +30,6 @@ class FluidbookGeneratePreview extends Command
     {
         //
         $f = FluidbookPublication::find($this->argument('id'));
-        $mobilefirstFluidbookId = $f->mobilefirstFluidbookId;
-        $fm = null;
-
-        $fn = 'dispatch';
-        if($this->argument('sync'))
-            $fn = 'dispatchSync';
-
-        if($mobilefirstFluidbookId) {
-            $fm = FluidbookPublication::find($mobilefirstFluidbookId);
-        }
-
-        if($fm) {
-            GenerateDeliveryThumbnailsPreview::$fn($fm,320, 600, 'mobile');
-        }
-
-        GenerateDeliveryThumbnailsPreview::$fn($f,1920, 1080);
-        GenerateDeliveryThumbnailsPreview::$fn($f,320, 600, 'mobile');
+        $f->generateThumbnailsPreview($this->option('sync', false));
     }
 }
index baf9f778669bef6be509ee71559e66406f4920b3..50171a2efadc2d919445439db8491e00e7d8c3d6 100644 (file)
@@ -7,6 +7,7 @@ use App\Http\Middleware\CheckIfAdmin;
 use App\Jobs\GenerateDeliveryThumbnailsPreview;
 use App\Models\FluidbookPublication;
 use Cubist\Backpack\Http\Controllers\Base\XSendFileController;
+use Cubist\Util\Files\Files;
 use Illuminate\Support\Facades\Route;
 use Prologue\Alerts\Facades\Alert;
 
@@ -45,14 +46,12 @@ trait DownloadOperation
             abort(404);
         }
 
-        $relayPath = '/fluidbookpublication/delivery/';
-        $relayPath = protected_path($relayPath);
+        $relayPath = Files::mkdir(protected_path('/fluidbookpublication/delivery/'));
         $relayPath .= $id;
         $relayPath .= $type === "desktop" ? '' : '-mobile';
         $relayPath .= '.jpg';
-        if(!file_exists($relayPath)) {
-            $f = FluidbookPublication::find($id);
-            $f->generateThumbnailsPreview(true);
+        if (!file_exists($relayPath)) {
+            (new GenerateDeliveryThumbnailsPreview(FluidbookPublication::withoutGlobalScopes()->find($id), $type === 'mobile' ? 'mobile' : ''))->handle();
         }
         return XSendFileController::sendfile($relayPath);
     }
index e464005affe3f33404af08889fa9a4fff68b87ae..5a264a4745a602798a77012dccba994f72066b01 100644 (file)
@@ -5,6 +5,7 @@ namespace App\Jobs;
 use App\Models\FluidbookPublication;
 use Cubist\Util\CommandLine;
 use Cubist\Util\Files\Files;
+use Illuminate\Support\Facades\Log;
 
 class GenerateDeliveryThumbnailsPreview extends Base
 {
@@ -13,11 +14,16 @@ class GenerateDeliveryThumbnailsPreview extends Base
     public $height;
     public $v;
 
-    public function __construct(FluidbookPublication $publication, $width, $height, $v = '')
+    public function __construct(FluidbookPublication $publication, $v = '')
     {
         $this->publication = $publication;
-        $this->width = $width;
-        $this->height = $height;
+        if(!$v) {
+            $this->width = 1920;
+            $this->height = 1201;
+        }else{
+            $this->width = 320;
+            $this->height = 683;
+        }
         $this->v = $v;
     }
 
@@ -27,7 +33,7 @@ class GenerateDeliveryThumbnailsPreview extends Base
     public function handle()
     {
         $cl = new CommandLine('node');
-        $cl->setArg(null, resource_path('fluidbooktheme/theme_preview/secondpage_preview.js'));
+        $cl->setArg(null, resource_path('fluidbookpublication/delivery/preview.js'));
         $cl->setArg('width', $this->width);
         $cl->setArg('height', $this->height);
         $cl->setArg('delay', 2);
@@ -37,6 +43,7 @@ class GenerateDeliveryThumbnailsPreview extends Base
         $url = $this->publication->getPreviewURL(['shortLoading' => 1, 'transition' => 1, 'puppeteer' => 1]);
         $cl->setArg('url', $url);
         $cl->execute();
+        $cl->debug();
     }
 
     public static function getPreviewPath($fluidbookId, $variant = '')
index 36bbe8ee33b24a292c77736bbbbd93a2c84aedf3..d928c89d1b033e38da98f1b133104192cb886753 100644 (file)
@@ -962,30 +962,31 @@ class FluidbookPublication extends ToolboxSettingsModel
     public function generateThumbnailsPreview($sync = false)
     {
         $mobilefirstFluidbookId = $this->mobilefirstFluidbookId;
-        $fm = null;
+        $mobileFirst = null;
 
         $fn = 'dispatch';
-        if ($sync)
+        if ($sync) {
             $fn = 'dispatchSync';
+        }
 
         if ($mobilefirstFluidbookId) {
-            $fm = self::find($mobilefirstFluidbookId);
+            $mobileFirst = self::withoutGlobalScopes()->find($mobilefirstFluidbookId);
         }
 
-        if ($fm) {
+        if ($mobileFirst) {
             if ($sync) {
-                GenerateDeliveryThumbnailsPreview::$fn($fm, 320, 683, 'mobile');
+                (new GenerateDeliveryThumbnailsPreview($mobileFirst,  'mobile'))->handle();
             } else {
-                dispatch(new GenerateDeliveryThumbnailsPreview($fm, 320, 683, 'mobile'))->onQueue('theme');
+                dispatch(new GenerateDeliveryThumbnailsPreview($mobileFirst,  'mobile'))->onQueue('theme');
             }
         }
 
         if ($sync) {
-            GenerateDeliveryThumbnailsPreview::$fn($this, 1920, 1201);
-            GenerateDeliveryThumbnailsPreview::$fn($this, 320, 683, 'mobile');
+            (new GenerateDeliveryThumbnailsPreview($this))->handle();
+            (new GenerateDeliveryThumbnailsPreview($this, 'mobile'))->handle();
         } else {
-            dispatch(new GenerateDeliveryThumbnailsPreview($this, 1920, 1201))->onQueue('theme');
-            dispatch(new GenerateDeliveryThumbnailsPreview($this, 320, 683, 'mobile'))->onQueue('theme');
+            dispatch(new GenerateDeliveryThumbnailsPreview($this, ))->onQueue('theme');
+            dispatch(new GenerateDeliveryThumbnailsPreview($this,  'mobile'))->onQueue('theme');
         }
     }
 
diff --git a/resources/fluidbookpublication/delivery/preview.js b/resources/fluidbookpublication/delivery/preview.js
new file mode 100644 (file)
index 0000000..4cae7d1
--- /dev/null
@@ -0,0 +1,38 @@
+const puppeteer = require('puppeteer');
+const commandLineArgs = require('command-line-args');
+const optionDefinitions = [
+    {name: 'url', type: String},
+    {name: 'dest', type: String},
+    {name: 'delay', type: Number, defaultOption: 10},
+    {name: 'scale', type: Number, defaultOption: 1},
+    {name: 'width', type: Number, defaultOption: 1920},
+    {name: 'height', type: Number, defaultOption: 1080},
+    {name: 'page', type: Number, defaultOption: 2}
+];
+
+(async () => {
+    const options = commandLineArgs(optionDefinitions);
+    const browser = await puppeteer.launch({
+        headless: true,
+        args: [
+            "--disable-setuid-sandbox",
+            "--no-sandbox",
+        ],
+        executablePath: 'google-chrome-stable',
+    });
+
+    const page = await browser.newPage();
+    await page.setDefaultNavigationTimeout(0);
+    await page.setViewport({
+        width: options.width / options.scale, height: options.height / options.scale, deviceScaleFactor: options.scale,
+    });
+    await page.goto(options.url, {waitUntil: 'networkidle2'});
+    //await page.waitForNavigation();
+    await new Promise(r => setTimeout(r, 1000 * (options.delay + 3)));
+    //
+    await page.evaluate(() => window.fluidbook.setCurrentPage(2));
+    await new Promise(r => setTimeout(r, 1000));
+    await page.screenshot({path: options.dest, type: 'jpeg', quality: 95});
+
+    await browser.close();
+})();
diff --git a/resources/fluidbooktheme/theme_preview/secondpage_preview.js b/resources/fluidbooktheme/theme_preview/secondpage_preview.js
deleted file mode 100644 (file)
index f2ec9b2..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-const puppeteer = require('puppeteer');
-const commandLineArgs = require('command-line-args');
-const optionDefinitions = [
-    {name: 'url', type: String},
-    {name: 'dest', type: String},
-    {name: 'delay', type: Number, defaultOption: 10},
-    {name: 'scale', type: Number, defaultOption: 1},
-    {name: 'width', type: Number, defaultOption: 1920},
-    {name: 'height', type: Number, defaultOption: 1080},
-    {name: 'page', type: Number, defaultOption: 2}
-];
-
-(async () => {
-    const options = commandLineArgs(optionDefinitions);
-    const browser = await puppeteer.launch({
-        headless: true,
-        args: [
-            "--disable-setuid-sandbox",
-            "--no-sandbox",
-        ],
-        executablePath: 'google-chrome-stable',
-    });
-
-    const page = await browser.newPage();
-    await page.setDefaultNavigationTimeout(0);
-    await page.setViewport({
-        width: options.width / options.scale, height: options.height / options.scale, deviceScaleFactor: options.scale,
-    });
-    await page.goto(options.url, {waitUntil: 'networkidle2'})
-    await page.waitForNavigation()
-    await new Promise(r => setTimeout(r, 1000 * (options.delay + 3)));
-    //
-    await page.evaluate(() => window.fluidbook.setCurrentPage(2));
-    await new Promise(r => setTimeout(r, 1000));
-    await page.screenshot({path: options.dest, type: 'jpeg', quality: 95});
-
-    await browser.close();
-})();
index 22cb1ddb9907e64dd6e6c28d82587e0e3cbd8823..370f4b8b9e06d6d98858a862c3f5f665940ecfbf 100644 (file)
@@ -89,7 +89,7 @@
     $enabledFeatures = array_filter($featuresSorted, function($n){ return $n['value'] !== "0" && !empty($n['value']); });
     $disabledFeatures = array_filter($featuresSorted, function($n){ return $n['value'] !== "1" && empty($n['value']); });
 
-    $icons = App\Models\FluidbookIconset::get('icons')->toArray();
+    $icons = App\Models\FluidbookIconset::withoutGlobalScopes()->get('icons')->toArray();
 
     $statUrl = route('stats', ['fluidbook_id' => $fluidbook->id, 'hash' => $fluidbook->hash]);
     $cid = $fluidbook->cid;
                 <div class="card position-sticky" style="top: 50px">
                     <div class="card-body">
                         <h2>{{ __('Publiez votre Fluidbook') }}</h2>
-                        <p>{{ __('L\'adresse d’hébergement a déjà été configurée, vous pouvez mettre votre Fluidbook
+                        @if($fluidbook->install_online && isset($serverName))
+                            <p>{{ __('L\'adresse d’hébergement a déjà été configurée, vous pouvez mettre votre Fluidbook
                             directement en ligne en cliquant ci-dessous :')}}</p>
-                        <div class="btn-install">
-                            <a href="{{ $prefixDownloadUrl.'/install/online' }}"
-                               class="btn btn-primary font-weight-normal text-left" rel="noopener">
-                                {!! __('Installer sur le serveur :server', ['server' => "<span class='font-weight-bold'>".$serverName."</span>"]) !!}
-                                <p class="m-0 font-xs font-weight-normal">{{ $installServerUrl }}</p>
-                            </a>
-                        </div>
+                            <div class="btn-install">
+                                <a href="{{ $prefixDownloadUrl.'/install/online' }}"
+                                   class="btn btn-primary font-weight-normal text-left" rel="noopener">
+                                    {!! __('Installer sur le serveur :server', ['server' => "<span class='font-weight-bold'>".$serverName."</span>"]) !!}
+                                    <p class="m-0 font-xs font-weight-normal">{{ $installServerUrl }}</p>
+                                </a>
+                            </div>
+                        @endif
                         <div class="delivery-dropdown position-relative">
                             <div class="dropdown-control d-flex justify-content-between">
                                 <span>{{ __('Téléchargez et installez votre Fluidbook') }}</span>