Updated logo API

This commit is contained in:
2026-04-23 21:32:25 +10:00
parent 110ed5b984
commit 678096b463
22 changed files with 638 additions and 146 deletions
@@ -0,0 +1,76 @@
<?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 AirlineApiController 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 getLogoByInternalName(string $internalName){
$airline = Airline::where('internal_name', $internalName)
->first();
return $this->getAirlineLogo($airline);
}
function parseAirlineData(Airline $airline){
$countryCode = $airline->country->code;
$result = $airline->toArray();
unset($result['id']);
unset($result['logo']);
unset($result['country_id']);
unset($result['country']);
$result['slug'] = $result['internal_name'];
unset($result['internal_name']);
$result['country_code'] = $countryCode;
return $result;
}
function getByCode(string $code){
$lookupColumn = strlen($code) === 3 ? 'ICAO_code' : 'IATA_code';
$airlines = Airline::where($lookupColumn, strtoupper($code))->get()->map(fn($airline) => $this->parseAirlineData($airline));
return response()->json($airlines);
}
function get(string $internalName){
$airline = Airline::where('internal_name', $internalName)->first();
return response()->json($this->parseAirlineData($airline));
}
}