Added Notifications
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class AircraftApiController extends Controller
|
||||
{
|
||||
public function getLivery(string $aircraftDesignator){
|
||||
$path = "images/livery_templates/{$aircraftDesignator}.png";
|
||||
return $this->imageIfExists($path);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -49,21 +49,8 @@ class AirlineApiController extends ApiController
|
||||
|
||||
public function getLivery(string $airlineInternalName, string $aircraftDesignator){
|
||||
$path = "images/liveries/{$airlineInternalName}_{$aircraftDesignator}.png";
|
||||
$cacheLimit = 60 * 60 * 72;
|
||||
|
||||
if(!Storage::disk('local')->exists($path)){
|
||||
return response()->json(['error' => 'Livery not found'], 404);
|
||||
}
|
||||
|
||||
$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),
|
||||
]);
|
||||
return $this->imageIfExists($path);
|
||||
}
|
||||
|
||||
function parseAirlineData(Airline $airline){
|
||||
|
||||
@@ -2,7 +2,23 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
abstract class Controller
|
||||
{
|
||||
//
|
||||
public function imageIfExists(string $path, $cacheLimit = 60 * 60 * 72){
|
||||
if(!Storage::disk('local')->exists($path)){
|
||||
return response()->json(['error' => 'Image not found'], 404);
|
||||
}
|
||||
|
||||
$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),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -275,7 +275,7 @@ class FlightController extends Controller
|
||||
return redirect()->route('profile.departure-board', [Auth::user()->name, $flight->id]);
|
||||
}
|
||||
|
||||
public function delete(UserFlight $flight)
|
||||
public function delete(UserFlight $flight, ?string $referrer = 'departure-board')
|
||||
{
|
||||
$this->authorize('delete', $flight);
|
||||
|
||||
@@ -296,7 +296,7 @@ class FlightController extends Controller
|
||||
]);
|
||||
|
||||
$flight->delete();
|
||||
return redirect()->route('profile.departure-board', [Auth::user()->name]);
|
||||
return redirect()->route('profile.'.$referrer, [Auth::user()->name]);
|
||||
}
|
||||
|
||||
public function staticData() : array {
|
||||
|
||||
@@ -52,10 +52,10 @@ class FlightProfileController extends Controller
|
||||
abort(404);
|
||||
}
|
||||
|
||||
|
||||
return Inertia::render('UserFlight', [
|
||||
'flightCount' => $user->flights()->count(),
|
||||
'flightCount' => $user->departedFlights()->count(),
|
||||
'flight' => $userFlight->snapshot($userFlight->id),
|
||||
'canEdit' => auth()->check() && auth()->id() === $user->id,
|
||||
'user' => $user,
|
||||
'isFollowing' => auth()->check() && auth()->user()->isFollowing($user),
|
||||
]);
|
||||
|
||||
@@ -227,17 +227,32 @@ class UserFlight extends Model
|
||||
return Attribute::make(
|
||||
get: function () {
|
||||
|
||||
if(!$this->airline || !$this->aircraft){
|
||||
$apiUrl = config('app.logo_api_url');
|
||||
|
||||
if (!$this->aircraft) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$path = "images/liveries/{$this->airline->internal_name}_{$this->aircraft->designator}.png";
|
||||
|
||||
if(!Storage::disk('local')->exists($path)){
|
||||
if ($this->airline){
|
||||
$path = "images/liveries/{$this->airline->internal_name}_{$this->aircraft->designator}.png";
|
||||
if (Storage::disk('local')->exists($path)) {
|
||||
$finalPath = $apiUrl."/airline/{$this->airline->internal_name}/livery/{$this->aircraft->designator}";
|
||||
}
|
||||
}
|
||||
|
||||
if(empty($finalPath)){
|
||||
$path = "images/livery_templates/{$this->aircraft->designator}.png";
|
||||
if (Storage::disk('local')->exists($path)) {
|
||||
$finalPath = $apiUrl."/aircraft/{$this->aircraft->designator}/livery";
|
||||
}
|
||||
}
|
||||
|
||||
if(empty($finalPath)){
|
||||
return null;
|
||||
}
|
||||
|
||||
return config('app.logo_api_url')."/airline/{$this->airline->internal_name}/livery/{$this->aircraft->designator}";
|
||||
return $finalPath;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user