diff --git a/VERSION.txt b/VERSION.txt index a478fd27a62e..e4714c19a557 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -5.0.25 \ No newline at end of file +5.0.26 \ No newline at end of file diff --git a/app/Http/Controllers/ClientPortal/TempRouteController.php b/app/Http/Controllers/ClientPortal/TempRouteController.php new file mode 100644 index 000000000000..d29a2c432c19 --- /dev/null +++ b/app/Http/Controllers/ClientPortal/TempRouteController.php @@ -0,0 +1,34 @@ +design($design) ->build(); + //if phantom js...... inject here.. + if (config('ninja.phantomjs_pdf_generation')) { + return (new Phantom)->convertHtmlToPdf($maker->getCompiledHTML(true)); + } + + //else $file_path = PreviewPdf::dispatchNow($maker->getCompiledHTML(true), auth()->user()->company()); return response()->download($file_path)->deleteFileAfterSend(true); @@ -192,6 +199,10 @@ class PreviewController extends BaseController ->design($design) ->build(); + if (config('ninja.phantomjs_pdf_generation')) { + return (new Phantom)->convertHtmlToPdf($maker->getCompiledHTML(true)); + } + $file_path = PreviewPdf::dispatchNow($maker->getCompiledHTML(true), auth()->user()->company()); DB::rollBack(); diff --git a/app/Utils/PhantomJS/Phantom.php b/app/Utils/PhantomJS/Phantom.php index c69511751323..6691142a042c 100644 --- a/app/Utils/PhantomJS/Phantom.php +++ b/app/Utils/PhantomJS/Phantom.php @@ -24,6 +24,8 @@ use App\Utils\Traits\MakesHash; use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\Storage; use Illuminate\Support\Str; +use Illuminate\Support\Facades\Response; +use Illuminate\Support\Facades\Cache; class Phantom { @@ -75,8 +77,6 @@ class Phantom $phantom_url = "https://phantomjscloud.com/api/browser/v2/{$key}/?request=%7Burl:%22{$url}%22,renderType:%22pdf%22%7D"; $pdf = CurlUtils::get($phantom_url); - //info($pdf); - Storage::makeDirectory($path, 0775); $instance = Storage::disk(config('filesystems.default'))->put($file_path, $pdf); @@ -84,6 +84,23 @@ class Phantom return $file_path; } + public function convertHtmlToPdf($html) + { + $hash = Str::random(32); + Cache::put($hash, $html, 300); + + $url = route('tmp_pdf', ['hash' => $hash]); +info($url); + $key = config('ninja.phantomjs_key'); + $phantom_url = "https://phantomjscloud.com/api/browser/v2/{$key}/?request=%7Burl:%22{$url}%22,renderType:%22pdf%22%7D"; + $pdf = CurlUtils::get($phantom_url); + + $response = Response::make($pdf, 200); + $response->header('Content-Type', 'application/pdf'); + + return $response; + } + public function displayInvitation(string $entity, string $invitation_key) { $key = $entity.'_id'; diff --git a/config/ninja.php b/config/ninja.php index b07123bea9bf..db67ee0b78df 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -12,7 +12,7 @@ return [ 'require_https' => env('REQUIRE_HTTPS', true), 'app_url' => rtrim(env('APP_URL', ''), '/').'/', 'app_domain' => env('APP_DOMAIN', ''), - 'app_version' => '5.0.25', + 'app_version' => '5.0.26', 'minimum_client_version' => '5.0.16', 'terms_version' => '1.0.1', 'api_secret' => env('API_SECRET', false), diff --git a/routes/client.php b/routes/client.php index 083befda64c3..782833015705 100644 --- a/routes/client.php +++ b/routes/client.php @@ -19,6 +19,8 @@ Route::get('view/{entity_type}/{invitation_key}', 'ClientPortal\EntityViewContro Route::get('view/{entity_type}/{invitation_key}/password', 'ClientPortal\EntityViewController@password')->name('client.entity_view.password'); Route::post('view/{entity_type}/{invitation_key}/password', 'ClientPortal\EntityViewController@handlePassword'); +Route::get('tmp_pdf/{hash}', 'ClientPortal\TempRouteController@index')->name('tmp_pdf'); + Route::get('client/key_login/{contact_key}', 'ClientPortal\ContactHashLoginController@login')->name('client.contact_login')->middleware(['contact_key_login']); //todo implement domain DB