From: Vincent Vanwaelscappel Date: Tue, 18 Jul 2023 07:46:05 +0000 (+0200) Subject: fix #6066 @0.75 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=33123815482a5b568140b3e118ab1f0cd81c33a4;p=fluidbook-toolbox.git fix #6066 @0.75 --- 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/fluidbookpublication/delivery/preview.js b/resources/fluidbookpublication/delivery/preview.js new file mode 100644 index 000000000..4cae7d123 --- /dev/null +++ b/resources/fluidbookpublication/delivery/preview.js @@ -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 index f2ec9b2c6..000000000 --- a/resources/fluidbooktheme/theme_preview/secondpage_preview.js +++ /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(); -})(); 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