1
0
Fork 0
mirror of https://codeberg.org/demostf/api.git synced 2026-06-03 18:04:08 +02:00

add basic api tests

This commit is contained in:
Robin Appelman 2017-07-16 01:12:07 +02:00
commit e00e6ece5f
30 changed files with 350 additions and 17 deletions

View file

@ -123,4 +123,8 @@ class Container {
public function getEditKey(): string {
return $this->editKey;
}
public function getConnection(): Connection {
return $this->connection;
}
}

View file

@ -82,19 +82,19 @@ class DemoController extends BaseController {
}
public function setDemoUrl($id) {
$hash = $this->query('hash', '');
$backend = $this->query('backend', '');
$path = $this->query('path', '');
$url = $this->query('url', '');
$editKey = $this->query('key', '');
if ($editKey !== $this->editKey) {
$hash = $this->post('hash', '');
$backend = $this->post('backend', '');
$path = $this->post('path', '');
$url = $this->post('url', '');
$editKey = $this->post('key', '');
if ($editKey !== $this->editKey || $editKey === '') {
throw new \InvalidArgumentException('Invalid key');
}
$demo = $this->demoProvider->get($id);
$demo = $this->demoProvider->get((int)$id);
$existingHash = $demo->getHash();
if ($existingHash === '' || $existingHash === $hash) {
$this->demoProvider->setDemoUrl($id, $backend, $url, $path);
$this->demoProvider->setDemoUrl((int)$id, $backend, $url, $path);
} else {
throw new \InvalidArgumentException('Invalid demo hash');
}

View file

@ -16,10 +16,19 @@ class UploadController extends BaseController {
$blu = $this->post('blu', 'BLU');
$name = $this->post('name', 'Unnamed');
$demo = $this->file('demo');
if (is_null($demo)) {
echo 'No demo uploaded';
return;
}
$demoFile = $demo['tmp_name'];
try {
echo $this->uploadProvider->upload($key, $red, $blu, $name, $demoFile);
$result = $this->uploadProvider->upload($key, $red, $blu, $name, $demoFile);
if ($result === 'Invalid key') {
\Flight::response()->status(401)->write($result)->send();
} else {
echo $result;
}
} catch (\Exception $e) {
\Flight::response()
->status(500)

View file

@ -42,9 +42,9 @@ 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('/demos/@id/url', [$demoController, 'setDemoUrl']);
Flight::route('/users/search', [$userController, 'search']);
Flight::route('/users/@steamid', [$userController, 'get']);

View file

@ -1,3 +1,3 @@
<?php
require '../app.php';
require __DIR__ . '/../app.php';