Skip to content
19 changes: 18 additions & 1 deletion backend/app/Helper/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,26 @@ public static function getApiUrl(string $path, array $queryParams = []): string
return self::addQueryParamsToUrl($queryParams, $url);
}

/**
* Generates a CDN URL for the given path if a CDN URL is configured.
* Falls back to generating a URL using the specified or default filesystem disk.
*
* @param string $path The relative path to the asset.
* @return string The fully qualified URL to the asset, either via CDN or storage disk.
*/
public static function getCdnUrl(string $path): string
{
return config('app.cnd_url') . '/' . $path;
// Fetch the CDN URL from environment variables
// Checking against the env variable instead of config() as config falls back to the default value
// and we want to ensure that if the env variable is not set, we do not use a default value.
$envCDNUrl = env('APP_CDN_URL');

if ($envCDNUrl) {
return $envCDNUrl . '/' . $path;
}

$disk = config('filesystems.public', 'public');
return app('filesystem')->disk($disk)->url($path);
}

private static function addQueryParamsToUrl(array $queryParams, mixed $url): mixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ public function handle(PartialUpdateEventSettingsDTO $eventSettingsDTO): EventSe

'order_timeout_in_minutes' => $eventSettingsDTO->settings['order_timeout_in_minutes'] ?? $existingSettings->getOrderTimeoutInMinutes(),
'website_url' => $eventSettingsDTO->settings['website_url'] ?? $existingSettings->getWebsiteUrl(),
'maps_url' => $eventSettingsDTO->settings['maps_url'] ?? $existingSettings->getMapsUrl(),
'maps_url' => array_key_exists('maps_url', $eventSettingsDTO->settings)
? $eventSettingsDTO->settings['maps_url']
: $existingSettings->getMapsUrl(),
'location_details' => $locationDetails,
'is_online_event' => $eventSettingsDTO->settings['is_online_event'] ?? $existingSettings->getIsOnlineEvent(),
'online_event_connection_details' => array_key_exists('online_event_connection_details', $eventSettingsDTO->settings)
Expand Down
2 changes: 1 addition & 1 deletion backend/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"php": "^8.2",
"ext-intl": "*",
"barryvdh/laravel-dompdf": "^3.0",
"brick/money": "^0.8.0",
"brick/money": "^0.10.1",
"doctrine/dbal": "^3.6",
"ezyang/htmlpurifier": "^4.17",
"guzzlehttp/guzzle": "^7.2",
Expand Down
Loading