- Full gg.deals-style UI: deal feed with filters, game pages with price history charts, rankings, vouchers, news, prepaids, subscriptions, bundles, franchises, wishlist, API docs - Real data crawlers: * gg:crawl (Steam Store API + GOG Catalog + Epic free games) * gg:catalog (252K game slugs from gg.deals sitemaps) * gg:ggdeals (per-game prices via FlareSolverr session, JSON-LD parsing) * gg:seed / gg:crawl-covers (demo seed + Steam CDN cover art) - 24/7 self-updating scheduler (scripts/scheduler_loop.php, lockfile-protected) - Tailwind v4 dark/light theme, Alpine.js, Chart.js
91 lines
3.0 KiB
PHP
91 lines
3.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Controllers;
|
|
|
|
use App\Libraries\Mongo;
|
|
use App\Models\GameModel;
|
|
use CodeIgniter\Controller;
|
|
|
|
class Api extends Controller
|
|
{
|
|
public function suggest(): \CodeIgniter\HTTP\ResponseInterface
|
|
{
|
|
$q = trim((string) service('request')->getGet('q'));
|
|
if (mb_strlen($q) < 2) {
|
|
return service('response')->setJSON([]);
|
|
}
|
|
|
|
return service('response')->setJSON((new GameModel())->suggest($q));
|
|
}
|
|
|
|
/**
|
|
* Game Prices API: lowest price by Steam App ID.
|
|
* GET /api/prices?appid=1245620
|
|
*/
|
|
public function prices(): \CodeIgniter\HTTP\ResponseInterface
|
|
{
|
|
$appid = (int) service('request')->getGet('appid');
|
|
if ($appid <= 0) {
|
|
return service('response')->setStatusCode(400)->setJSON([
|
|
'error' => 'bad_request',
|
|
'message' => 'Missing or invalid "appid" query parameter.',
|
|
]);
|
|
}
|
|
|
|
// appid map is in the CrawlCovers command; reuse via a public map.
|
|
$game = (new GameModel())->findByAppId($appid);
|
|
if ($game === null) {
|
|
return service('response')->setStatusCode(404)->setJSON([
|
|
'error' => 'not_found',
|
|
'message' => "No game found for Steam App ID {$appid}.",
|
|
]);
|
|
}
|
|
|
|
return service('response')->setJSON([
|
|
'game' => [
|
|
'title' => $game['title'],
|
|
'slug' => $game['slug'],
|
|
'url' => '/game/' . $game['slug'],
|
|
'steam_appid' => $appid,
|
|
'regular_price' => (float) $game['base_price'],
|
|
'best_official' => [
|
|
'price' => (float) $game['best_official']['price'],
|
|
'store' => $game['best_official']['store'],
|
|
'cut' => (int) $game['best_official']['cut'],
|
|
],
|
|
'best_keyshop' => [
|
|
'price' => (float) $game['best_keyshop']['price'],
|
|
'store' => $game['best_keyshop']['store'],
|
|
'cut' => (int) $game['best_keyshop']['cut'],
|
|
],
|
|
'all_time_low' => [
|
|
'price' => (float) $game['all_time_low']['price'],
|
|
'store' => $game['all_time_low']['store'],
|
|
'date' => $game['all_time_low']['date'] instanceof \MongoDB\BSON\UTCDateTime
|
|
? $game['all_time_low']['date']->toDateTime()->format('Y-m-d')
|
|
: null,
|
|
],
|
|
'active_deals' => (int) $game['active_deals'],
|
|
'metacritic' => (int) $game['score'],
|
|
],
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* API documentation page data (regions, endpoints).
|
|
*/
|
|
public function docs(): string
|
|
{
|
|
$model = new GameModel();
|
|
|
|
$data = [
|
|
'pageTitle' => 'GG.deals API — Game Deals, Bundles and Prices API',
|
|
'stats' => $model->stats(),
|
|
];
|
|
|
|
return view('api', $data);
|
|
}
|
|
}
|