]> _ Git - fluidbook-toolbox.git/commitdiff
wip #6606 @7:00
authorsoufiane <soufiane@cubedesigners.com>
Tue, 27 Jun 2023 17:30:05 +0000 (19:30 +0200)
committersoufiane <soufiane@cubedesigners.com>
Tue, 27 Jun 2023 17:30:05 +0000 (19:30 +0200)
app/Console/Commands/DebugDeliveryJob.php [new file with mode: 0644]
app/Jobs/GenerateSecondPagePreview.php
app/Models/FluidbookPublication.php
resources/fluidbooktheme/theme_preview/secondpage_preview.js
resources/views/fluidbook_publication/delivery.blade.php
scripts/dockerterminal-dev.bat
storage/delivery/30116.jpg [new file with mode: 0644]

diff --git a/app/Console/Commands/DebugDeliveryJob.php b/app/Console/Commands/DebugDeliveryJob.php
new file mode 100644 (file)
index 0000000..305822c
--- /dev/null
@@ -0,0 +1,34 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Jobs\GenerateSecondPagePreview;
+use Illuminate\Console\Command;
+use App\Models\FluidbookPublication;
+
+class DebugDeliveryJob extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'app:debug-delivery-job';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = 'Command description';
+
+    /**
+     * Execute the console command.
+     */
+    public function handle()
+    {
+        //
+        $f = FluidbookPublication::find(30116);
+        GenerateSecondPagePreview::dispatchSync($f);
+    }
+}
index 2e6785f54e7bebc6343c3f1ede302094553337be..af5df6a155d35a34b54cb9d500748f22459fdf34 100644 (file)
@@ -2,33 +2,60 @@
 
 namespace App\Jobs;
 
-use App\Models\FluidbookTheme;
+use App\Models\FluidbookPublication;
 use Cubist\Util\CommandLine;
 
 class GenerateSecondPagePreview extends Base
 {
-    public $width;
+    public $publication;
 
-    public function __construct($width = 1920)
+    public function __construct(FluidbookPublication $publication)
     {
-        $this->width = $width;
+        $this->publication = $publication;
     }
 
     /**
      * Execute the job.
      */
-    public function handle(): void
+    public function handle()
     {
         $cl = new CommandLine('node');
         $cl->setArg(null, resource_path('fluidbooktheme/theme_preview/secondpage_preview.js'));
-        $cl->setArg('width', $this->width);
+        $cl->setArg('width', 1920);
         $cl->setArg('height', 1080);
         $cl->setArg('delay', 2);
         $cl->setArg('scale', 1);
-        $cl->setArg('dest', self::getPreviewPath($this->theme->getIdValue()));
+        $cl->setArg('dest', self::getPreviewPath($this->publication->id));
         $cl->setArg('page', 2);
-        $url = $this->theme->getPreviewURL(['shortLoading' => 1, 'transition' => 1, 'puppeteer' => 1]);
+        $url = $this->publication->getPreviewURL();
         $cl->setArg('url', $url);
+
+        $cl2 = new CommandLine('node');
+        $cl2->setArg(null, resource_path('fluidbooktheme/theme_preview/secondpage_preview.js'));
+        $cl2->setArg('width', 320);
+        $cl2->setArg('height', 600);
+        $cl2->setArg('delay', 2);
+        $cl2->setArg('scale', 1);
+        $cl2->setArg('dest', self::getPreviewPath($this->publication->id), "mobile");
+        $cl2->setArg('page', 2);
+        $url = $this->publication->getPreviewURL();
+        $cl2->setArg('url', $url);
+
+
         $cl->execute();
+        $cl2->execute();
+
+
+        $cl->dd();
+    }
+
+    public static function getPreviewPath($fluidbookId, $variant = '')
+    {
+        $res = storage_path('delivery') . '/' . $fluidbookId;
+        if ($variant) {
+            $res .= '-' . $variant;
+        }
+        $res .= '.jpg';
+        return $res;
     }
 }
index fb10edc20dd02d823422959b110c97ab2bb1e7b8..b7442f71750fb7c1ae1edca1f23981ee783064a1 100644 (file)
@@ -26,6 +26,7 @@ use App\Http\Controllers\Admin\Operations\FluidbookPublication\Services\ExportPd
 use App\Http\Controllers\Admin\Operations\FluidbookPublication\Services\SocialImageOperation;
 use App\Http\Controllers\Admin\Operations\FluidbookPublication\StatsOperation;
 use App\Jobs\FluidbookImagesPreprocess;
+use App\Jobs\GenerateSecondPagePreview;
 use App\Models\Base\ToolboxSettingsModel;
 use App\Models\Traits\CheckHash;
 use App\Models\Traits\PublicationSettings;
@@ -264,6 +265,8 @@ class FluidbookPublication extends ToolboxSettingsModel
     {
         $this->setComposedAttributes();
         $this->checkHash();
+
+        dispatch(new GenerateSecondPagePreview($this))->onQueue('theme');
         if ($this->_compositionUpdated) {
             FluidbookImagesPreprocess::dispatch($this->id);
         }
index 5cfc362b58a88e90ae116357ac26e8fa79cb8f01..a0c3e23d3489f699eb14c4ae98035742f8ad65fa 100644 (file)
@@ -22,24 +22,16 @@ const optionDefinitions = [
     });
 
     const page = await browser.newPage();
-    page.on('console', async (msg) => {
-        const msgArgs = msg.args();
-        for (let i = 0; i < msgArgs.length; ++i) {
-            console.log(await msgArgs[i].jsonValue());
-        }
-    });
     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.screenshot({path: options.dest, type: 'jpeg', quality: 95});
+    await page.goto(options.url, {waitUntil: 'networkidle2'})
+    await page.waitForNavigation()
     await new Promise(r => setTimeout(r, 1000 * (options.delay + 3)));
-    await page.evaluate(() => console.log(document.body.innerHTML));
-    // Move to page 2
+    //
     await page.evaluate(() => window.fluidbook.setCurrentPage(2));
-    // Wait 1s and take a screenshot
-    await new Promise(r => setTimeout(r, 2000));
+    await new Promise(r => setTimeout(r, 1000));
+    await page.screenshot({path: options.dest, type: 'jpeg', quality: 95});
 
     await browser.close();
 })();
index 35814bbf3a5e3e38637767ca556f2e25d69872c6..9643712ee74c5d9180cb4a220be4c8e0d8834d27 100644 (file)
@@ -1,6 +1,7 @@
 @extends(backpack_view('blank'))
 
 @php
+dd(storage_path('delivery') . '/');
     $breadcrumbs = [
         trans('backpack::crud.admin') => url(config('backpack.base.route_prefix'), 'dashboard'),
         trans('backpack::base.my_account') => false,
index 0a6645eace27d6fba459a2e3bb68118a9dbbc1e1..fc637b919d6762313b96c292088e28c6d3cd8d66 100644 (file)
@@ -1,3 +1,3 @@
 @echo off
 cls
-C:\tools\cygwin\bin\ssh.exe -t root@dev.toolbox.fluidbook.com 'docker exec -it -u toolbox fluidbook-toolbox-dev /bin/bash'
+ssh -t root@dev.toolbox.fluidbook.com 'docker exec -it -u toolbox fluidbook-toolbox-dev /bin/bash'
diff --git a/storage/delivery/30116.jpg b/storage/delivery/30116.jpg
new file mode 100644 (file)
index 0000000..172d364
Binary files /dev/null and b/storage/delivery/30116.jpg differ