mirror of
https://codeberg.org/demostf/api.git
synced 2026-06-03 18:04:08 +02:00
add api to set demo url
This commit is contained in:
parent
b588c8ce7e
commit
64b0aff075
6 changed files with 87 additions and 4 deletions
|
|
@ -27,6 +27,7 @@ class Container {
|
|||
private $storeRoot;
|
||||
private $storeUrl;
|
||||
private $apiRoot;
|
||||
private $editKey;
|
||||
|
||||
public function __construct(
|
||||
Connection $connection,
|
||||
|
|
@ -35,7 +36,8 @@ class Container {
|
|||
string $parserUrl,
|
||||
string $storeRoot,
|
||||
string $storeUrl,
|
||||
string $apiRoot
|
||||
string $apiRoot,
|
||||
string $editKey
|
||||
) {
|
||||
$this->connection = $connection;
|
||||
$this->generator = $generator;
|
||||
|
|
@ -44,6 +46,7 @@ class Container {
|
|||
$this->storeRoot = $storeRoot;
|
||||
$this->storeUrl = $storeUrl;
|
||||
$this->apiRoot = $apiRoot;
|
||||
$this->editKey = $editKey;
|
||||
}
|
||||
|
||||
public function getAuthProvider(): AuthProvider {
|
||||
|
|
@ -116,4 +119,8 @@ class Container {
|
|||
public function getApiRoot(): string {
|
||||
return $this->apiRoot;
|
||||
}
|
||||
|
||||
public function getEditKey(): string {
|
||||
return $this->editKey;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,10 +14,13 @@ class DemoController extends BaseController {
|
|||
|
||||
private $demoListProvider;
|
||||
|
||||
public function __construct(DemoProvider $demoProvider, ChatProvider $chatProvider, DemoListProvider $demoListProvider) {
|
||||
private $editKey;
|
||||
|
||||
public function __construct(DemoProvider $demoProvider, ChatProvider $chatProvider, DemoListProvider $demoListProvider, string $editKey) {
|
||||
$this->demoProvider = $demoProvider;
|
||||
$this->chatProvider = $chatProvider;
|
||||
$this->demoListProvider = $demoListProvider;
|
||||
$this->editKey = $editKey;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -77,4 +80,23 @@ class DemoController extends BaseController {
|
|||
public function chat($demoId) {
|
||||
\Flight::json($this->chatProvider->getChat($demoId));
|
||||
}
|
||||
|
||||
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) {
|
||||
throw new \InvalidArgumentException('Invalid key');
|
||||
}
|
||||
|
||||
$demo = $this->demoProvider->get($id);
|
||||
$existingHash = $demo->getHash();
|
||||
if ($existingHash === '' || $existingHash === $hash) {
|
||||
$this->demoProvider->setDemoUrl($id, $backend, $url, $path);
|
||||
} else {
|
||||
throw new \InvalidArgumentException('Invalid demo hash');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -81,4 +81,14 @@ class DemoProvider extends BaseProvider {
|
|||
->execute();
|
||||
return (int)$this->connection->lastInsertId();
|
||||
}
|
||||
|
||||
public function setDemoUrl(int $id, string $backend, string $url, string $path) {
|
||||
$query = $this->getQueryBuilder();
|
||||
$query->update('demos')
|
||||
->set('backend', $query->createNamedParameter($backend))
|
||||
->set('url', $query->createNamedParameter($url))
|
||||
->set('path', $query->createNamedParameter($path))
|
||||
->where($query->expr()->eq('id', $query->createNamedParameter($id, \PDO::PARAM_INT)))
|
||||
->execute();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,8 @@ $container = require __DIR__ . '/init.php';
|
|||
$demoController = new Controllers\DemoController(
|
||||
$container->getDemoProvider(),
|
||||
$container->getChatProvider(),
|
||||
$container->getDemoListProvider()
|
||||
$container->getDemoListProvider(),
|
||||
$container->getEditKey()
|
||||
);
|
||||
$authController = new Controllers\AuthController(
|
||||
$container->getUserProvider(),
|
||||
|
|
@ -43,6 +44,7 @@ Flight::route('/demos/@id', [$demoController, 'get']);
|
|||
Flight::route('/demos/@id/chat', [$demoController, 'chat']);
|
||||
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']);
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ $storeRoot = getenv('DEMO_ROOT') ?: '';
|
|||
$storeHost = getenv('DEMO_HOST') ?: '';
|
||||
$parserUrl = getenv('PARSER_URL') ?: '';
|
||||
$appRoot = getenv('APP_ROOT') ?: '';
|
||||
$editKey = getenv('EDIT_SECRET') ?: '';
|
||||
|
||||
$factory = new \RandomLib\Factory;
|
||||
$generator = $factory->getMediumStrengthGenerator();
|
||||
|
|
@ -36,7 +37,8 @@ $container = new Container(
|
|||
$parserUrl,
|
||||
$storeRoot,
|
||||
$storeHost,
|
||||
$appRoot
|
||||
$appRoot,
|
||||
$editKey
|
||||
);
|
||||
|
||||
return $container;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue