mirror of
https://codeberg.org/demostf/api.git
synced 2026-06-03 18:04:08 +02:00
split off infocontroller
This commit is contained in:
parent
7a6ff09eee
commit
66d177e23a
6 changed files with 55 additions and 36 deletions
|
|
@ -70,12 +70,4 @@ class DemoController extends BaseController {
|
||||||
public function chat($demoId) {
|
public function chat($demoId) {
|
||||||
\Flight::json($this->demoProvider->getChat($demoId));
|
\Flight::json($this->demoProvider->getChat($demoId));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function listMaps() {
|
|
||||||
\Flight::json($this->demoProvider->listMaps());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stats() {
|
|
||||||
\Flight::json($this->demoProvider->getStats());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
25
src/Controllers/InfoController.php
Normal file
25
src/Controllers/InfoController.php
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
<?php namespace Demostf\API\Controllers;
|
||||||
|
|
||||||
|
use Demostf\API\Providers\InfoProvider;
|
||||||
|
|
||||||
|
class InfoController extends BaseController {
|
||||||
|
/** @var InfoProvider */
|
||||||
|
private $infoProvider;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* InfoController constructor.
|
||||||
|
*
|
||||||
|
* @param InfoProvider $infoProvider
|
||||||
|
*/
|
||||||
|
public function __construct(InfoProvider $infoProvider) {
|
||||||
|
$this->infoProvider = $infoProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function listMaps() {
|
||||||
|
\Flight::json($this->infoProvider->listMaps());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function stats() {
|
||||||
|
\Flight::json($this->infoProvider->getStats());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -19,7 +19,7 @@ class AuthProvider extends BaseProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setUser($token, \SteamId $steamid, $key) {
|
public function setUser($token, \SteamId $steamid, $key) {
|
||||||
apc_store($token, [
|
apcu_store($token, [
|
||||||
'name' => $steamid->getNickname(),
|
'name' => $steamid->getNickname(),
|
||||||
'steamid' => $steamid->getSteamId64(),
|
'steamid' => $steamid->getSteamId64(),
|
||||||
'key' => $key
|
'key' => $key
|
||||||
|
|
@ -28,8 +28,8 @@ class AuthProvider extends BaseProvider {
|
||||||
|
|
||||||
public function getUser($token) {
|
public function getUser($token) {
|
||||||
$found = true;
|
$found = true;
|
||||||
$result = apc_fetch($token, $found);
|
$result = apcu_fetch($token, $found);
|
||||||
return ($found) ? $result : ['name' => null, 'steamid' => null, 'key' => null];
|
return $found ? $result : ['name' => null, 'steamid' => null, 'key' => null];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function logout($token) {
|
public function logout($token) {
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,5 @@
|
||||||
<?php namespace Demostf\API\Providers;
|
<?php namespace Demostf\API\Providers;
|
||||||
|
|
||||||
use Demostf\API\Demo\Header;
|
|
||||||
use Demostf\API\Demo\IDemoStore;
|
|
||||||
use Demostf\API\Demo\StoredDemo;
|
|
||||||
use Doctrine\DBAL\Connection;
|
use Doctrine\DBAL\Connection;
|
||||||
|
|
||||||
class DemoProvider extends BaseProvider {
|
class DemoProvider extends BaseProvider {
|
||||||
|
|
@ -99,12 +96,6 @@ class DemoProvider extends BaseProvider {
|
||||||
return $this->formatList($demos);
|
return $this->formatList($demos);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function listMaps() {
|
|
||||||
$sql = 'SELECT DISTINCT(map), COUNT(map) AS count from demos GROUP BY map ORDER BY count DESC';
|
|
||||||
$result = $this->query($sql);
|
|
||||||
return $result->fetchAll(\PDO::FETCH_COLUMN);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getChat($demoId) {
|
public function getChat($demoId) {
|
||||||
$chat = $this->db->chat()->where('demo_id', $demoId);
|
$chat = $this->db->chat()->where('demo_id', $demoId);
|
||||||
$result = [];
|
$result = [];
|
||||||
|
|
@ -161,20 +152,6 @@ class DemoProvider extends BaseProvider {
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getStats() {
|
|
||||||
$demoCount = $this->db->demo()->count();
|
|
||||||
$playerCount = $this->db->user()->count();
|
|
||||||
|
|
||||||
$sql = 'SELECT count(user_id) FROM players GROUP BY user_id';
|
|
||||||
$result = $this->query($sql);
|
|
||||||
|
|
||||||
return [
|
|
||||||
'demos' => $demoCount,
|
|
||||||
'players' => $playerCount,
|
|
||||||
'uploaders' => $result->fetchColumn()
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function demoIdByHash($hash) {
|
public function demoIdByHash($hash) {
|
||||||
$query = $this->getQueryBuilder();
|
$query = $this->getQueryBuilder();
|
||||||
$query->select('hash')
|
$query->select('hash')
|
||||||
|
|
|
||||||
23
src/Providers/InfoProvider.php
Normal file
23
src/Providers/InfoProvider.php
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
<?php namespace Demostf\API\Providers;
|
||||||
|
|
||||||
|
class InfoProvider extends BaseProvider {
|
||||||
|
public function listMaps() {
|
||||||
|
$sql = 'SELECT DISTINCT(map), COUNT(map) AS count from demos GROUP BY map ORDER BY count DESC';
|
||||||
|
$result = $this->query($sql);
|
||||||
|
return $result->fetchAll(\PDO::FETCH_COLUMN);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getStats() {
|
||||||
|
$demoCount = $this->db->demo()->count();
|
||||||
|
$playerCount = $this->db->user()->count();
|
||||||
|
|
||||||
|
$sql = 'SELECT count(user_id) FROM players GROUP BY user_id';
|
||||||
|
$result = $this->query($sql);
|
||||||
|
|
||||||
|
return [
|
||||||
|
'demos' => $demoCount,
|
||||||
|
'players' => $playerCount,
|
||||||
|
'uploaders' => $result->fetchColumn()
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -25,9 +25,11 @@ $factory = new \RandomLib\Factory;
|
||||||
$generator = $factory->getMediumStrengthGenerator();
|
$generator = $factory->getMediumStrengthGenerator();
|
||||||
$authProvider = new Providers\AuthProvider($db, $generator);
|
$authProvider = new Providers\AuthProvider($db, $generator);
|
||||||
$userProvider = new Providers\UserProvider($db, $generator);
|
$userProvider = new Providers\UserProvider($db, $generator);
|
||||||
|
$infoProvider = new Providers\InfoProvider($db);
|
||||||
$demoController = new Controllers\DemoController($demoProvider);
|
$demoController = new Controllers\DemoController($demoProvider);
|
||||||
$authController = new Controllers\AuthController($userProvider, $authProvider, $host);
|
$authController = new Controllers\AuthController($userProvider, $authProvider, $host);
|
||||||
$userController = new Controllers\UserController($userProvider);
|
$userController = new Controllers\UserController($userProvider);
|
||||||
|
$infoController = new Controllers\InfoController($infoProvider);
|
||||||
|
|
||||||
Flight::route('/*', function () {
|
Flight::route('/*', function () {
|
||||||
header('Access-Control-Allow-Origin: *');
|
header('Access-Control-Allow-Origin: *');
|
||||||
|
|
@ -43,8 +45,8 @@ Flight::route('/', function () {
|
||||||
echo 'hello world!';
|
echo 'hello world!';
|
||||||
});
|
});
|
||||||
|
|
||||||
Flight::route('/maps', [$demoController, 'listMaps']);
|
Flight::route('/maps', [$infoController, 'listMaps']);
|
||||||
Flight::route('/stats', [$demoController, 'stats']);
|
Flight::route('/stats', [$infoController, 'stats']);
|
||||||
|
|
||||||
Flight::route('/demos', [$demoController, 'listDemos']);
|
Flight::route('/demos', [$demoController, 'listDemos']);
|
||||||
Flight::route('/demos/@id', [$demoController, 'get']);
|
Flight::route('/demos/@id', [$demoController, 'get']);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue