From 33123815482a5b568140b3e118ab1f0cd81c33a4 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Tue, 18 Jul 2023 09:46:05 +0200 Subject: [PATCH] fix #6066 @0.75 --- .../Commands/FluidbookGeneratePreview.php | 20 ++---------------- .../DownloadOperation.php | 9 ++++---- .../GenerateDeliveryThumbnailsPreview.php | 15 +++++++++---- app/Models/FluidbookPublication.php | 21 ++++++++++--------- .../delivery/preview.js} | 4 ++-- .../delivery/index.blade.php | 20 ++++++++++-------- 6 files changed, 41 insertions(+), 48 deletions(-) rename resources/{fluidbooktheme/theme_preview/secondpage_preview.js => fluidbookpublication/delivery/preview.js} (92%) diff --git a/app/Console/Commands/FluidbookGeneratePreview.php b/app/Console/Commands/FluidbookGeneratePreview.php index 73a595e06..1f9ab63e4 100644 --- a/app/Console/Commands/FluidbookGeneratePreview.php +++ b/app/Console/Commands/FluidbookGeneratePreview.php @@ -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)); } } diff --git a/app/Http/Controllers/Admin/Operations/FluidbookPublication/DownloadOperation.php b/app/Http/Controllers/Admin/Operations/FluidbookPublication/DownloadOperation.php index baf9f7786..50171a2ef 100644 --- a/app/Http/Controllers/Admin/Operations/FluidbookPublication/DownloadOperation.php +++ b/app/Http/Controllers/Admin/Operations/FluidbookPublication/DownloadOperation.php @@ -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); } diff --git a/app/Jobs/GenerateDeliveryThumbnailsPreview.php b/app/Jobs/GenerateDeliveryThumbnailsPreview.php index e464005af..5a264a474 100644 --- a/app/Jobs/GenerateDeliveryThumbnailsPreview.php +++ b/app/Jobs/GenerateDeliveryThumbnailsPreview.php @@ -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 = '') diff --git a/app/Models/FluidbookPublication.php b/app/Models/FluidbookPublication.php index 36bbe8ee3..d928c89d1 100644 --- a/app/Models/FluidbookPublication.php +++ b/app/Models/FluidbookPublication.php @@ -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/fluidbooktheme/theme_preview/secondpage_preview.js b/resources/fluidbookpublication/delivery/preview.js similarity index 92% rename from resources/fluidbooktheme/theme_preview/secondpage_preview.js rename to resources/fluidbookpublication/delivery/preview.js index f2ec9b2c6..4cae7d123 100644 --- a/resources/fluidbooktheme/theme_preview/secondpage_preview.js +++ b/resources/fluidbookpublication/delivery/preview.js @@ -26,8 +26,8 @@ const optionDefinitions = [ 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 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)); diff --git a/resources/views/fluidbook_publication/delivery/index.blade.php b/resources/views/fluidbook_publication/delivery/index.blade.php index 22cb1ddb9..370f4b8b9 100644 --- a/resources/views/fluidbook_publication/delivery/index.blade.php +++ b/resources/views/fluidbook_publication/delivery/index.blade.php @@ -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; @@ -459,15 +459,17 @@

{{ __('Publiez votre Fluidbook') }}

-

{{ __('L\'adresse d’hébergement a déjà été configurée, vous pouvez mettre votre Fluidbook + @if($fluidbook->install_online && isset($serverName)) +

{{ __('L\'adresse d’hébergement a déjà été configurée, vous pouvez mettre votre Fluidbook directement en ligne en cliquant ci-dessous :')}}

- + + @endif