1
0
Fork 0
mirror of https://codeberg.org/demostf/api.git synced 2026-06-03 18:04:08 +02:00
This commit is contained in:
Robin Appelman 2019-04-12 14:00:20 +02:00
commit 73469d2aa1
29 changed files with 140 additions and 149 deletions

View file

@ -7,8 +7,10 @@ namespace Demostf\API\Controllers;
use Ehesp\SteamLogin\SteamLogin;
use Demostf\API\Providers\AuthProvider;
use Demostf\API\Providers\UserProvider;
use Flight;
use flight\net\Request;
use flight\net\Response;
use SteamId;
class AuthController extends BaseController {
/**
@ -47,7 +49,7 @@ class AuthController extends BaseController {
public function get($token) {
$userData = $this->authProvider->getUser($token);
\Flight::json([
Flight::json([
'token' => $token,
'steamid' => $userData['steamid'],
'name' => $userData['name'],
@ -59,12 +61,12 @@ class AuthController extends BaseController {
$_SESSION['return'] = $this->query('return', 'https://' . $this->host);
$steam = new SteamLogin();
$url = $steam->url($this->apiRoot . '/auth/handle/' . urlencode($token), $this->apiRoot);
\Flight::redirect(str_replace('&', '&', $url)); // headers make no sense
Flight::redirect(str_replace('&', '&', $url)); // headers make no sense
}
public function logout($token) {
$this->authProvider->logout($token);
\Flight::json([
Flight::json([
'token' => $token,
'steamid' => null,
'name' => null,
@ -78,10 +80,10 @@ class AuthController extends BaseController {
$steam = new SteamLogin();
$steamId = $steam->validate();
if ($steamId) {
$steamIdObject = new \SteamId($steamId);
$steamIdObject = new SteamId($steamId);
$key = $this->userProvider->store($steamIdObject);
$this->authProvider->setUser($token, $steamIdObject, $key);
}
\Flight::redirect($return);
Flight::redirect($return);
}
}

View file

@ -10,6 +10,9 @@ use Demostf\API\Providers\DemoListProvider;
use Demostf\API\Providers\DemoProvider;
use flight\net\Request;
use flight\net\Response;
use function intval;
use InvalidArgumentException;
use function is_array;
class DemoController extends BaseController {
/** @var DemoProvider */
@ -45,7 +48,7 @@ class DemoController extends BaseController {
* @param string $id
*/
public function get($id) {
$this->json($this->demoProvider->get(\intval($id, 10)));
$this->json($this->demoProvider->get(intval($id, 10)));
}
protected function getFilter() {
@ -61,7 +64,7 @@ class DemoController extends BaseController {
$filter['backend'] = $backend;
}
if ($players) {
if (!\is_array($players)) {
if (!is_array($players)) {
$players = explode(',', $players);
}
$players = array_filter($players);
@ -123,7 +126,7 @@ class DemoController extends BaseController {
$url = (string) $this->post('url', '');
$editKey = (string) $this->post('key', '');
if ($editKey !== $this->editKey || '' === $editKey) {
throw new \InvalidArgumentException('Invalid key');
throw new InvalidArgumentException('Invalid key');
}
$demo = $this->demoProvider->get((int) $id);
@ -135,7 +138,7 @@ class DemoController extends BaseController {
$this->store->remove($demo);
}
} else {
throw new \InvalidArgumentException('Invalid demo hash');
throw new InvalidArgumentException('Invalid demo hash');
}
}
}

View file

@ -5,6 +5,7 @@ declare(strict_types=1);
namespace Demostf\API\Controllers;
use Demostf\API\Providers\InfoProvider;
use Flight;
use flight\net\Request;
use flight\net\Response;
@ -18,10 +19,10 @@ class InfoController extends BaseController {
}
public function listMaps() {
\Flight::json($this->infoProvider->listMaps());
Flight::json($this->infoProvider->listMaps());
}
public function stats() {
\Flight::json($this->infoProvider->getStats());
Flight::json($this->infoProvider->getStats());
}
}

View file

@ -1,53 +0,0 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2018 Robin Appelman <robin@icewind.nl>
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Demostf\API\Controllers;
class TempController extends BaseController {
private $webRoot;
public function __construct(string $webRoot) {
$this->webRoot = $webRoot;
}
public function register(string $key, string $path): string {
apcu_store($key, $path);
return $this->webRoot . $key;
}
public function unregister(string $key) {
apcu_dec($key);
}
public function serve(string $key) {
$path = apcu_fetch($key);
if ($path) {
$handle = fopen($path, 'r');
fpassthru($handle);
fclose($handle);
} else {
\Flight::response()
->status(404)
->send();
}
}
}

View file

@ -5,6 +5,8 @@ declare(strict_types=1);
namespace Demostf\API\Controllers;
use Demostf\API\Providers\UploadProvider;
use Exception;
use Flight;
use flight\net\Request;
use flight\net\Response;
@ -32,12 +34,12 @@ class UploadController extends BaseController {
try {
$result = $this->uploadProvider->upload($key, $red, $blu, $name, $demoFile);
if ('Invalid key' === $result) {
\Flight::response()->status(401)->write($result)->send();
Flight::response()->status(401)->write($result)->send();
} else {
echo $result;
}
} catch (\Exception $e) {
\Flight::response()
} catch (Exception $e) {
Flight::response()
->status(500)
->write($e->getMessage())
->send();

View file

@ -6,8 +6,10 @@ namespace Demostf\API\Controllers;
use Demostf\API\Demo\Parser;
use Demostf\API\Providers\UserProvider;
use Flight;
use flight\net\Request;
use flight\net\Response;
use InvalidArgumentException;
class UserController extends BaseController {
/**
@ -24,14 +26,14 @@ class UserController extends BaseController {
if (!is_numeric($steamId)) {
try {
$steamId = Parser::convertSteamIdToCommunityId($steamId);
} catch (\InvalidArgumentException $e) {
} catch (InvalidArgumentException $e) {
}
}
\Flight::json($this->userProvider->get($steamId));
Flight::json($this->userProvider->get($steamId));
}
public function search() {
$query = $this->query('query', '');
\Flight::json($this->userProvider->search($query));
Flight::json($this->userProvider->search($query));
}
}