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
{
{
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'];