]> _ Git - fluidbook-toolbox.git/commitdiff
wip #7834 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 14 Nov 2025 13:12:34 +0000 (14:12 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 14 Nov 2025 13:12:34 +0000 (14:12 +0100)
app/Http/Controllers/Admin/Operations/FluidbookPublication/Services/PumaOperation.php

index dada8119ca991ffcf6f2a72c1819ad0221eea4bb..d14d9842e5ade197e3ff9a61fb82545efd808f53 100644 (file)
@@ -7,9 +7,11 @@ use App\Http\Middleware\CheckIfAdmin;
 use App\Http\Middleware\VerifyCsrfToken;
 use App\Models\FluidbookPublication;
 use Cubist\Backpack\Middleware\CORSMiddleware;
+use Cubist\Util\Cache;
 use Cubist\Util\CommandLine;
 use Cubist\Util\Files\Files;
 use Illuminate\Support\Facades\Route;
+use function Psy\sh;
 
 trait PumaOperation
 {
@@ -17,20 +19,39 @@ trait PumaOperation
     {
         foreach (['services', 's'] as $s) {
             Route::get($s . '/puma/planogramme/{id}_{cid}/{references}/{format?}/{filename?}/{pa?}/{pvp?}', $controller . '@pumaPlanogramme')->middleware([CORSMiddleware::class])->withoutMiddleware([CheckIfAdmin::class, Authenticate::class, VerifyCsrfToken::class]);
+            Route::get($s . '/puma/planogrammehash/{id}_{cid}/{hash}/{format?}/{filename?}/{pa?}/{pvp?}', $controller . '@pumaPlanogrammeHash')->middleware([CORSMiddleware::class])->withoutMiddleware([CheckIfAdmin::class, Authenticate::class, VerifyCsrfToken::class]);
+            Route::post($s . '/puma/planogramme/{id}_{cid}/{format?}/{filename?}/{pa?}/{pvp?}', $controller . '@pumaPlanogrammePost')->middleware([CORSMiddleware::class])->withoutMiddleware([CheckIfAdmin::class, Authenticate::class, VerifyCsrfToken::class]);
         }
     }
 
+    protected function pumaPlanogrammePost($id, $cid, $format = 'html', $filename = '', $pa = 1, $pvp = 1)
+    {
+        return $this->pumaPlanogramme($id, $cid, request()->post('references'), $format, $filename, $pa, $pvp);
+    }
+
+    protected function pumaPlanogrammeHash($id, $cid, $hash, $format = 'html', $filename = '', $pa = 1, $pvp = 1)
+    {
+        $references = cache()->get('puma_planogramme_' . $hash);
+        return $this->pumaPlanogramme($id, $cid, $references, $format, $filename, $pa, $pvp);
+    }
+
     protected function pumaPlanogramme($id, $cid, $references, $format = 'html', $filename = '', $pa = 1, $pvp = 1)
     {
+        $references = str_replace("+", " ", $references);
         if ($format === 'pdf') {
             $tmp = Files::tempnam() . '.pdf';
 
+            $r = sha1($references);
+            cache()->forever('puma_planogramme_' . $r, $references);
+
+            $url = 'https://' . $_SERVER['HTTP_HOST'] . '/s/puma/planogrammehash/' . $id . '_' . $cid . '/' . $r . '/html/' . rawurlencode($filename) . '/' . $pa . '/' . $pvp;
+
             $cl = new CommandLine('node');
             $cl->setArg(null, resource_path('puma/planogramme/print.js'));
-            $cl->setArg('url', 'https://' . $_SERVER['HTTP_HOST'] . '/s/puma/planogramme/' . $id . '_' . $cid . '/' . rawurlencode($references) . '/html/' . $filename . '/' . $pa . '/' . $pvp);
+            $cl->setArg('url', $url);
             $cl->setArg('output', $tmp);
             $cl->execute();
-            return response()->download($tmp, $filename . '.pdf')->deleteFileAfterSend(true);
+            return response()->download($tmp, $filename . '.pdf');
         }
 
         $bottomStrings = ['shorts', 'pants', 'tights', 'leggings', 'skirts', 'socks'];