mirror of
https://codeberg.org/demostf/api.git
synced 2026-06-03 18:04:08 +02:00
81 lines
2.5 KiB
PHP
81 lines
2.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Demostf\API;
|
|
|
|
use Demostf\API\Error\InvalidHashException;
|
|
use Demostf\API\Error\InvalidKeyException;
|
|
use Flight;
|
|
|
|
/** @var Container $container */
|
|
$container = require __DIR__ . '/init.php';
|
|
|
|
$demoController = new Controllers\DemoController(
|
|
$container->getRequest(),
|
|
$container->getResponse(),
|
|
$container->getDemoProvider(),
|
|
$container->getChatProvider(),
|
|
$container->getDemoListProvider(),
|
|
$container->getDemoStore(),
|
|
$container->getEditKey()
|
|
);
|
|
$authController = new Controllers\AuthController(
|
|
$container->getRequest(),
|
|
$container->getResponse(),
|
|
$container->getUserProvider(),
|
|
$container->getAuthProvider(),
|
|
$container->getBaseUrl(),
|
|
$container->getApiRoot()
|
|
);
|
|
$userController = new Controllers\UserController($container->getRequest(), $container->getResponse(),
|
|
$container->getUserProvider());
|
|
$infoController = new Controllers\InfoController($container->getRequest(), $container->getResponse(),
|
|
$container->getInfoProvider());
|
|
|
|
Flight::route('/*', function () {
|
|
header('Access-Control-Allow-Origin: *');
|
|
|
|
return true;
|
|
});
|
|
|
|
Flight::route('/auth/*', function () {
|
|
session_start();
|
|
|
|
return true;
|
|
});
|
|
|
|
Flight::route('/', function () {
|
|
echo 'hello world!';
|
|
});
|
|
|
|
Flight::route('/maps', [$infoController, 'listMaps']);
|
|
Flight::route('/stats', [$infoController, 'stats']);
|
|
|
|
Flight::route('/demos', [$demoController, 'listDemos']);
|
|
Flight::route('/demos/@id', [$demoController, 'get']);
|
|
Flight::route('/demos/@id/chat', [$demoController, 'chat']);
|
|
Flight::route('/demos/@id/url', [$demoController, 'setDemoUrl']);
|
|
Flight::route('/profiles/@steamid', [$demoController, 'listProfile']);
|
|
Flight::route('/uploads/@steamid', [$demoController, 'listUploads']);
|
|
|
|
Flight::route('/users/search', [$userController, 'search']);
|
|
Flight::route('/users/@steamid', [$userController, 'get']);
|
|
|
|
Flight::route('/auth/token', [$authController, 'token']);
|
|
Flight::route('/auth/get/@token', [$authController, 'get']);
|
|
Flight::route('/auth/handle/@token', [$authController, 'handle']);
|
|
Flight::route('/auth/login/@token', [$authController, 'login']);
|
|
Flight::route('/auth/logout/@token', [$authController, 'logout']);
|
|
|
|
Flight::map('error', function (\Exception $ex) {
|
|
$code = 500;
|
|
if ($ex instanceof InvalidKeyException) {
|
|
$code = 401;
|
|
} elseif ($ex instanceof InvalidHashException) {
|
|
$code = 412;
|
|
}
|
|
Flight::response()->status($code)->write($ex->getMessage())->send();
|
|
});
|
|
|
|
Flight::start();
|