mirror of
https://codeberg.org/demostf/api.git
synced 2026-06-03 18:04:08 +02:00
stricter cs
This commit is contained in:
parent
309ae17036
commit
d9a843ecd6
54 changed files with 346 additions and 168 deletions
|
|
@ -1,9 +1,12 @@
|
|||
<?php namespace Demostf\API\Controllers;
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Demostf\API\Controllers;
|
||||
|
||||
use Ehesp\SteamLogin\SteamLogin;
|
||||
use Demostf\API\Providers\AuthProvider;
|
||||
use Demostf\API\Providers\UserProvider;
|
||||
use flight\Engine;
|
||||
|
||||
class AuthController extends BaseController {
|
||||
/**
|
||||
|
|
@ -38,7 +41,7 @@ class AuthController extends BaseController {
|
|||
'token' => $token,
|
||||
'steamid' => $userData['steamid'],
|
||||
'name' => $userData['name'],
|
||||
'key' => $userData['key']
|
||||
'key' => $userData['key'],
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
@ -55,7 +58,7 @@ class AuthController extends BaseController {
|
|||
'token' => $token,
|
||||
'steamid' => null,
|
||||
'name' => null,
|
||||
'key' => null
|
||||
'key' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,18 +1,25 @@
|
|||
<?php namespace Demostf\API\Controllers;
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Demostf\API\Controllers;
|
||||
|
||||
class BaseController {
|
||||
protected function query($name, $default) {
|
||||
$request = \Flight::request();
|
||||
|
||||
return isset($request->query[$name]) ? $request->query[$name] : $default;
|
||||
}
|
||||
|
||||
protected function file($name) {
|
||||
$request = \Flight::request();
|
||||
|
||||
return $request->files[$name];
|
||||
}
|
||||
|
||||
protected function post($name, $default = null) {
|
||||
$request = \Flight::request();
|
||||
|
||||
return isset($request->data[$name]) ? $request->data[$name] : $default;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,12 @@
|
|||
<?php namespace Demostf\API\Controllers;
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Demostf\API\Controllers;
|
||||
|
||||
use Demostf\API\Providers\ChatProvider;
|
||||
use Demostf\API\Providers\DemoListProvider;
|
||||
use Demostf\API\Providers\DemoProvider;
|
||||
use flight\Engine;
|
||||
|
||||
class DemoController extends BaseController {
|
||||
/** @var DemoProvider */
|
||||
|
|
@ -16,7 +19,12 @@ class DemoController extends BaseController {
|
|||
|
||||
private $editKey;
|
||||
|
||||
public function __construct(DemoProvider $demoProvider, ChatProvider $chatProvider, DemoListProvider $demoListProvider, string $editKey) {
|
||||
public function __construct(
|
||||
DemoProvider $demoProvider,
|
||||
ChatProvider $chatProvider,
|
||||
DemoListProvider $demoListProvider,
|
||||
string $editKey
|
||||
) {
|
||||
$this->demoProvider = $demoProvider;
|
||||
$this->chatProvider = $chatProvider;
|
||||
$this->demoListProvider = $demoListProvider;
|
||||
|
|
@ -24,10 +32,10 @@ class DemoController extends BaseController {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param string $id
|
||||
* @param string $id
|
||||
*/
|
||||
public function get($id) {
|
||||
\Flight::json($this->demoProvider->get($id));
|
||||
\Flight::json($this->demoProvider->get(intval($id, 10)));
|
||||
}
|
||||
|
||||
protected function getFilter() {
|
||||
|
|
@ -56,6 +64,7 @@ class DemoController extends BaseController {
|
|||
$filter['playerCount'] = [7, 8, 9];
|
||||
break;
|
||||
}
|
||||
|
||||
return $filter;
|
||||
}
|
||||
|
||||
|
|
@ -65,16 +74,16 @@ class DemoController extends BaseController {
|
|||
\Flight::json($this->demoListProvider->listDemos($page, $this->getFilter(), $order));
|
||||
}
|
||||
|
||||
public function listProfile($steamid) {
|
||||
public function listProfile($steamId) {
|
||||
$page = $this->query('page', 1);
|
||||
$where = $this->getFilter();
|
||||
$where['players'][] = $steamid;
|
||||
$where['players'][] = $steamId;
|
||||
\Flight::json($this->demoListProvider->listProfile($page, $where));
|
||||
}
|
||||
|
||||
public function listUploads($steamid) {
|
||||
public function listUploads($steamId) {
|
||||
$page = $this->query('page', 1);
|
||||
\Flight::json($this->demoListProvider->listUploads($steamid, $page, $this->getFilter()));
|
||||
\Flight::json($this->demoListProvider->listUploads($steamId, $page, $this->getFilter()));
|
||||
}
|
||||
|
||||
public function chat($demoId) {
|
||||
|
|
@ -82,19 +91,19 @@ class DemoController extends BaseController {
|
|||
}
|
||||
|
||||
public function setDemoUrl($id) {
|
||||
$hash = $this->post('hash', '');
|
||||
$backend = $this->post('backend', '');
|
||||
$path = $this->post('path', '');
|
||||
$url = $this->post('url', '');
|
||||
$editKey = $this->post('key', '');
|
||||
$hash = (string) $this->post('hash', '');
|
||||
$backend = (string) $this->post('backend', '');
|
||||
$path = (string) $this->post('path', '');
|
||||
$url = (string) $this->post('url', '');
|
||||
$editKey = (string) $this->post('key', '');
|
||||
if ($editKey !== $this->editKey || $editKey === '') {
|
||||
throw new \InvalidArgumentException('Invalid key');
|
||||
}
|
||||
|
||||
$demo = $this->demoProvider->get((int)$id);
|
||||
$demo = $this->demoProvider->get((int) $id);
|
||||
$existingHash = $demo->getHash();
|
||||
if ($existingHash === '' || $existingHash === $hash) {
|
||||
$this->demoProvider->setDemoUrl((int)$id, $backend, $url, $path);
|
||||
$this->demoProvider->setDemoUrl((int) $id, $backend, $url, $path);
|
||||
} else {
|
||||
throw new \InvalidArgumentException('Invalid demo hash');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,10 @@
|
|||
<?php namespace Demostf\API\Controllers;
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Demostf\API\Controllers;
|
||||
|
||||
use Demostf\API\Providers\InfoProvider;
|
||||
use flight\Engine;
|
||||
|
||||
class InfoController extends BaseController {
|
||||
/** @var InfoProvider */
|
||||
|
|
|
|||
|
|
@ -1,7 +1,10 @@
|
|||
<?php namespace Demostf\API\Controllers;
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Demostf\API\Controllers;
|
||||
|
||||
use Demostf\API\Providers\UploadProvider;
|
||||
use flight\Engine;
|
||||
|
||||
class UploadController extends BaseController {
|
||||
private $uploadProvider;
|
||||
|
|
@ -11,13 +14,14 @@ class UploadController extends BaseController {
|
|||
}
|
||||
|
||||
public function upload() {
|
||||
$key = $this->post('key', '');
|
||||
$red = $this->post('red', 'RED');
|
||||
$blu = $this->post('blu', 'BLU');
|
||||
$name = $this->post('name', 'Unnamed');
|
||||
$key = (string) $this->post('key', '');
|
||||
$red = (string) $this->post('red', 'RED');
|
||||
$blu = (string) $this->post('blu', 'BLU');
|
||||
$name = (string) $this->post('name', 'Unnamed');
|
||||
$demo = $this->file('demo');
|
||||
if (is_null($demo)) {
|
||||
if (null === $demo) {
|
||||
echo 'No demo uploaded';
|
||||
|
||||
return;
|
||||
}
|
||||
$demoFile = $demo['tmp_name'];
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
<?php namespace Demostf\API\Controllers;
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Demostf\API\Controllers;
|
||||
|
||||
use Ehesp\SteamLogin\SteamLogin;
|
||||
use Demostf\API\Providers\AuthProvider;
|
||||
use Demostf\API\Providers\UserProvider;
|
||||
use flight\Engine;
|
||||
|
||||
class UserController extends BaseController {
|
||||
/**
|
||||
|
|
@ -15,8 +16,8 @@ class UserController extends BaseController {
|
|||
$this->userProvider = $userProvider;
|
||||
}
|
||||
|
||||
public function get($steamid) {
|
||||
\Flight::json($this->userProvider->get($steamid));
|
||||
public function get($steamId) {
|
||||
\Flight::json($this->userProvider->get($steamId));
|
||||
}
|
||||
|
||||
public function search() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue