Expand branding controls and logo upload
This commit is contained in:
@@ -349,9 +349,14 @@ class EventController extends Controller
|
||||
$validated['settings']['watermark_allowed'] = $watermarkAllowed;
|
||||
|
||||
$settings = $validated['settings'];
|
||||
$branding = Arr::get($settings, 'branding', []);
|
||||
$watermark = Arr::get($settings, 'watermark', []);
|
||||
$existingWatermark = is_array($watermark) ? $watermark : [];
|
||||
|
||||
if (is_array($branding)) {
|
||||
$settings['branding'] = $this->normalizeBrandingSettings($branding, $event, $brandingAllowed);
|
||||
}
|
||||
|
||||
if (is_array($watermark)) {
|
||||
$mode = $watermark['mode'] ?? 'base';
|
||||
$policy = $watermarkAllowed ? 'basic' : 'none';
|
||||
@@ -442,6 +447,68 @@ class EventController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $branding
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function normalizeBrandingSettings(array $branding, Event $event, bool $brandingAllowed): array
|
||||
{
|
||||
$logoDataUrl = $branding['logo_data_url'] ?? null;
|
||||
|
||||
if (! $brandingAllowed) {
|
||||
unset($branding['logo_data_url']);
|
||||
|
||||
return $branding;
|
||||
}
|
||||
|
||||
if (! is_string($logoDataUrl) || trim($logoDataUrl) === '') {
|
||||
unset($branding['logo_data_url']);
|
||||
|
||||
return $branding;
|
||||
}
|
||||
|
||||
if (! preg_match('/^data:image\\/(png|webp|jpe?g);base64,(.+)$/i', $logoDataUrl, $matches)) {
|
||||
throw ValidationException::withMessages([
|
||||
'settings.branding.logo_data_url' => __('Ungültiges Branding-Logo.'),
|
||||
]);
|
||||
}
|
||||
|
||||
$decoded = base64_decode($matches[2], true);
|
||||
|
||||
if ($decoded === false) {
|
||||
throw ValidationException::withMessages([
|
||||
'settings.branding.logo_data_url' => __('Branding-Logo konnte nicht gelesen werden.'),
|
||||
]);
|
||||
}
|
||||
|
||||
if (strlen($decoded) > 1024 * 1024) { // 1 MB
|
||||
throw ValidationException::withMessages([
|
||||
'settings.branding.logo_data_url' => __('Branding-Logo ist zu groß (max. 1 MB).'),
|
||||
]);
|
||||
}
|
||||
|
||||
$extension = str_starts_with(strtolower($matches[1]), 'jp') ? 'jpg' : strtolower($matches[1]);
|
||||
$path = sprintf('branding/logos/event-%s.%s', $event->id, $extension);
|
||||
Storage::disk('public')->put($path, $decoded);
|
||||
|
||||
$branding['logo_url'] = $path;
|
||||
$branding['logo_mode'] = 'upload';
|
||||
$branding['logo_value'] = $path;
|
||||
|
||||
$logo = $branding['logo'] ?? [];
|
||||
if (! is_array($logo)) {
|
||||
$logo = [];
|
||||
}
|
||||
|
||||
$logo['mode'] = 'upload';
|
||||
$logo['value'] = $path;
|
||||
$branding['logo'] = $logo;
|
||||
|
||||
unset($branding['logo_data_url']);
|
||||
|
||||
return $branding;
|
||||
}
|
||||
|
||||
public function destroy(Request $request, Event $event): JsonResponse
|
||||
{
|
||||
$tenantId = $request->attributes->get('tenant_id');
|
||||
|
||||
Reference in New Issue
Block a user