79 lines
2.2 KiB
PHP
79 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
use App\Http\Controllers\ApiController;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Airline;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
class LogoController extends ApiController
|
|
{
|
|
const array CONDOR_LOGOS = ['BEACH', 'ISLAND', 'PASSION', 'SEA', 'SUNSHINE'];
|
|
|
|
public function getAirlineLogo(?Airline $airline)
|
|
{
|
|
$logoFile = $airline?->logo ?? 'blank.png';
|
|
$cacheLimit = 60 * 60 * 24;
|
|
|
|
if ($airline?->internal_name == 'condor') {
|
|
$logoKey = array_rand(self::CONDOR_LOGOS);
|
|
$logoFile = 'DE_' . self::CONDOR_LOGOS[$logoKey] . '.png';
|
|
$cacheLimit = 1;
|
|
}
|
|
|
|
$path = 'images/logos/tail/' . $logoFile;
|
|
if (!Storage::disk('local')->exists($path)) {
|
|
$path = 'images/logos/tail/blank.png';
|
|
}
|
|
|
|
$fullPath = Storage::disk('local')->path($path);
|
|
$lastModified = filemtime($fullPath);
|
|
|
|
return response()->file($fullPath, [
|
|
'Content-Type' => 'image/png',
|
|
'Cache-Control' => 'public, max-age='.$cacheLimit, // 24 hours
|
|
'Last-Modified' => gmdate('D, d M Y H:i:s', $lastModified) . ' GMT',
|
|
'ETag' => md5($path . $lastModified),
|
|
]);
|
|
}
|
|
|
|
public function getLogoById($id){
|
|
$airline = Airline::where('id', $id)
|
|
->first();
|
|
|
|
return $this->getAirlineLogo($airline);
|
|
}
|
|
|
|
public function getLogoByInternalName(string $internalName){
|
|
$airline = Airline::where('internal_name', $internalName)
|
|
->first();
|
|
|
|
return $this->getAirlineLogo($airline);
|
|
}
|
|
|
|
|
|
public function getLogoByCode(string $code){
|
|
|
|
$column = strlen($code) == 2
|
|
? 'IATA_code'
|
|
: 'ICAO_code';
|
|
|
|
$airline = Airline::where($column, strtoupper($code))
|
|
->whereNotNull('logo')
|
|
->where('active', true)
|
|
->latest('id')
|
|
->first();
|
|
|
|
if (!$airline) {
|
|
$airline = Airline::where($column, strtoupper($code))
|
|
->whereNotNull('logo')
|
|
->latest('id')
|
|
->first();
|
|
}
|
|
|
|
return $this->getAirlineLogo($airline);
|
|
}
|
|
}
|