mirror of
https://github.com/rico-vz/HeimerdingerLoL.git
synced 2025-12-06 02:00:48 +01:00
feat(sales): add sales feature toggle
This commit is contained in:
@@ -87,3 +87,7 @@ VITE_PUSHER_HOST="${PUSHER_HOST}"
|
|||||||
VITE_PUSHER_PORT="${PUSHER_PORT}"
|
VITE_PUSHER_PORT="${PUSHER_PORT}"
|
||||||
VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"
|
VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"
|
||||||
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
|
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
|
||||||
|
|
||||||
|
# Enable or disable fetching live Sale Rotation data from the external API.
|
||||||
|
# Set to true to enable fetching, false to show the maintenance message.
|
||||||
|
SALES_ENABLED=false
|
||||||
|
|||||||
@@ -4,24 +4,29 @@ namespace App\Http\Controllers;
|
|||||||
|
|
||||||
use Illuminate\Support\Facades\Cache;
|
use Illuminate\Support\Facades\Cache;
|
||||||
use Illuminate\Support\Facades\Http;
|
use Illuminate\Support\Facades\Http;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
class SaleController extends Controller
|
class SaleController extends Controller
|
||||||
{
|
{
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
|
// If the feature toggle is disabled, do not attempt to fetch sales data and return the maintenance view.
|
||||||
|
if (!config('sales.enabled')) {
|
||||||
|
return view('sales.index');
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$sales = Cache::remember('sales_data', 60 * 60 * 8, static function () {
|
$sales = Cache::remember('sales_data', 60 * 60 * 8, static function () {
|
||||||
$lmi_api_key = config('services.lmi.api_key');
|
$lmi_api_key = config('services.lmi.api_key');
|
||||||
|
|
||||||
$response = Http::withHeaders([
|
$response = Http::withHeaders([
|
||||||
'Authorization' => 'Bearer '.$lmi_api_key,
|
'Authorization' => 'Bearer ' . $lmi_api_key,
|
||||||
])->get('https://lmi.orianna.dev/api/lol-sales');
|
])->get('https://lmi.orianna.dev/api/lol-sales');
|
||||||
|
|
||||||
$response = $response->json();
|
$response = $response->json();
|
||||||
|
|
||||||
if ($response['champion_sales'] === null) {
|
if (! isset($response['champion_sales']) || $response['champion_sales'] === null) {
|
||||||
logger()->error('LMI has broken');
|
Log::error('LMI has broken');
|
||||||
|
|
||||||
return abort(503, 'Trying to access array offset on value of type null');
|
return abort(503, 'Trying to access array offset on value of type null');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,14 +34,15 @@ class SaleController extends Controller
|
|||||||
});
|
});
|
||||||
} catch (\Exception $exception) {
|
} catch (\Exception $exception) {
|
||||||
if ($exception->getMessage() === 'Trying to access array offset on value of type null') {
|
if ($exception->getMessage() === 'Trying to access array offset on value of type null') {
|
||||||
logger()->error('LMI has broken');
|
Log::error('LMI has broken');
|
||||||
abort(503, 'Sorry, the Sale Rotation is currently under maintenance. Please try again later.');
|
abort(503, 'Sorry, the Sale Rotation is currently under maintenance. Please try again later.');
|
||||||
} else {
|
} else {
|
||||||
logger()->error('An error occurred while trying to fetch the Sale Rotation', ['error' => $exception->getMessage()]);
|
Log::error('An error occurred while trying to fetch the Sale Rotation', ['error' => $exception->getMessage()]);
|
||||||
abort(500, 'Sorry, an error occurred while trying to fetch the Sale Rotation. Please try again later.');
|
abort(500, 'Sorry, an error occurred while trying to fetch the Sale Rotation. Please try again later.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return view('sales.index', ['sales' => $sales]);
|
return view('sales.index', ['sales' => $sales]);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
17
config/sales.php
Normal file
17
config/sales.php
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
return [
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Sales page feature toggle
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Enable or disable fetching of the external Sale Rotation data. When set to
|
||||||
|
| true, the app will attempt to fetch sale rotation data from the external
|
||||||
|
| API. When false, the sales page will show a maintenance message and no
|
||||||
|
| external requests are made.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'enabled' => env('SALES_ENABLED', false),
|
||||||
|
];
|
||||||
@@ -6,6 +6,15 @@
|
|||||||
and skins are currently on sale and grab a good deal!')
|
and skins are currently on sale and grab a good deal!')
|
||||||
|
|
||||||
@section('content')
|
@section('content')
|
||||||
<x-sales.current_sales :sales="$sales" />
|
@isset($sales)
|
||||||
|
<x-sales.current_sales :sales="$sales" />
|
||||||
|
@else
|
||||||
|
<section class="max-w-screen-xl mx-auto mt-12">
|
||||||
|
<h1
|
||||||
|
class="text-3xl font-bold text-center text-transparent uppercase sm:text-4xl bg-gradient-to-bl from-orange-300 to-orange-500 bg-clip-text">
|
||||||
|
Sale Rotation</h1>
|
||||||
|
<p class="mt-6 text-lg text-center text-white">Sale Rotation is currently under construction due to breaking changes. We are sorry</p>
|
||||||
|
</section>
|
||||||
|
@endisset
|
||||||
<x-buymeacoffee.floating />
|
<x-buymeacoffee.floating />
|
||||||
@endsection
|
@endsection
|
||||||
|
|||||||
Reference in New Issue
Block a user