Feat(Gotenberg): Opt-in alternative pdf generation for modern CSS (#184)

* WIP(gotenberg): add pdf generation abstraction and UI

* feat(pdf): settings validate(clien+server) & save

* fix(gotenberg): Use correct default papersize
chore(gotengberg): Remove unused GOTENBERG_MARGINS env from .env

* style(gotenberg): fix linter/styling issues

* fix(pdf): use pdf config policy

* fix: revert accidental capitalization in mail config vue

* Update composer, remove whitespace typo

* Fix small typos

* fix cookie/env issue

* Add gotenberg to .dev, move admin menu item up
This commit is contained in:
Tim van Osch
2025-05-04 02:10:15 +02:00
committed by GitHub
parent 8a9392e400
commit bf40f792c2
27 changed files with 1512 additions and 597 deletions

View File

@@ -6,6 +6,7 @@ use App\Http\Requests\DatabaseEnvironmentRequest;
use App\Http\Requests\DiskEnvironmentRequest;
use App\Http\Requests\DomainEnvironmentRequest;
use App\Http\Requests\MailEnvironmentRequest;
use App\Http\Requests\PDFConfigurationRequest;
use Exception;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\DB;
@@ -94,7 +95,6 @@ class EnvironmentManager
}
return $str;
}
/**
@@ -225,7 +225,6 @@ class EnvironmentManager
try {
$this->updateEnv($mailEnv);
} catch (Exception $e) {
return [
'error' => 'mail_variables_save_error',
@@ -237,6 +236,60 @@ class EnvironmentManager
];
}
/**
* Save the pdf generation content to the .env file.
*
* @return array
*/
public function savePDFVariables(PDFConfigurationRequest $request)
{
$pdfEnv = $this->getPDFConfiguration($request);
try {
$this->updateEnv($pdfEnv);
} catch (Exception $e) {
return [
'error' => 'pdf_variables_save_error',
];
}
return [
'success' => 'pdf_variables_save_successfully',
];
}
/**
* Returns the pdf configuration
*
* @param PDFConfigurationRequest $request
* @return array
*/
private function getPDFConfiguration($request)
{
$pdfEnv = [];
$driver = $request->get('pdf_driver');
switch ($driver) {
case 'dompdf':
$pdfEnv = [
'PDF_DRIVER' => $request->get('pdf_driver'),
];
break;
case 'gotenberg':
$pdfEnv = [
'PDF_DRIVER' => $request->get('pdf_driver'),
'GOTENBERG_HOST' => $request->get('gotenberg_host'),
'GOTENBERG_MARGINS' => $request->get('gotenberg_margins'),
'GOTENBERG_PAPERSIZE' => $request->get('gotenberg_papersize'),
];
break;
}
return $pdfEnv;
}
/**
* Returns the mail configuration
*
@@ -316,7 +369,6 @@ class EnvironmentManager
];
break;
}
return $mailEnv;
@@ -334,7 +386,6 @@ class EnvironmentManager
try {
$this->updateEnv($diskEnv);
} catch (Exception $e) {
return [
'error' => 'disk_variables_save_error',
@@ -450,7 +501,6 @@ class EnvironmentManager
}
$formatted .= $current.$this->delimiter;
$previous = $current;
}
file_put_contents($this->envPath, trim($formatted));