From db9b42dc7a57806c97876212eca53a805d23b7bc Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Fri, 14 Nov 2025 14:12:34 +0100 Subject: [PATCH] wip #7834 @1 --- .../Services/PumaOperation.php | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Admin/Operations/FluidbookPublication/Services/PumaOperation.php b/app/Http/Controllers/Admin/Operations/FluidbookPublication/Services/PumaOperation.php index dada8119c..d14d9842e 100644 --- a/app/Http/Controllers/Admin/Operations/FluidbookPublication/Services/PumaOperation.php +++ b/app/Http/Controllers/Admin/Operations/FluidbookPublication/Services/PumaOperation.php @@ -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']; -- 2.39.5