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-01-23 18:56:44 +01:00
commit c29fe61ad1
24 changed files with 1242 additions and 50 deletions

View file

@ -45,7 +45,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 +61,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);
@ -96,7 +96,7 @@ class DemoController extends BaseController {
public function listDemos() {
$page = $this->query('page', 1);
$order = $this->query('order', 'DESC') === 'ASC' ? 'ASC' : 'DESC';
$order = 'ASC' === $this->query('order', 'DESC') ? 'ASC' : 'DESC';
$this->json($this->demoListProvider->listDemos((int) $page, $this->getFilter(), $order));
}
@ -122,16 +122,16 @@ class DemoController extends BaseController {
$path = (string) $this->post('path', '');
$url = (string) $this->post('url', '');
$editKey = (string) $this->post('key', '');
if ($editKey !== $this->editKey || $editKey === '') {
if ($editKey !== $this->editKey || '' === $editKey) {
throw new \InvalidArgumentException('Invalid key');
}
$demo = $this->demoProvider->get((int) $id);
$existingHash = $demo->getHash();
if ($existingHash === '' || $existingHash === $hash) {
if ('' === $existingHash || $existingHash === $hash) {
$this->demoProvider->setDemoUrl((int) $id, $backend, $url, $path);
if ($demo->getBackend() === 'static') {
if ('static' === $demo->getBackend()) {
$this->store->remove($demo);
}
} else {

View file

@ -1,7 +1,8 @@
<?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
@ -16,12 +17,10 @@
*
* 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;
@ -29,8 +28,9 @@ class TempController extends BaseController {
$this->webRoot = $webRoot;
}
public function register(string $key, string $path) : string {
public function register(string $key, string $path): string {
apcu_store($key, $path);
return $this->webRoot . $key;
}

View file

@ -31,7 +31,7 @@ class UploadController extends BaseController {
try {
$result = $this->uploadProvider->upload($key, $red, $blu, $name, $demoFile);
if ($result === 'Invalid key') {
if ('Invalid key' === $result) {
\Flight::response()->status(401)->write($result)->send();
} else {
echo $result;