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

allow access key to access private demos

This commit is contained in:
Robin Appelman 2025-05-03 15:45:22 +02:00
commit 52b9bc09fd
10 changed files with 37 additions and 52 deletions

View file

@ -34,6 +34,7 @@ class Container {
private Request $request;
private Response $response;
private string $uploadKey;
private string $accessKey;
public function __construct(
Request $request,
@ -46,7 +47,8 @@ class Container {
string $storeUrl,
string $apiRoot,
string $editKey,
string $uploadKey
string $uploadKey,
string $accessKey,
) {
$this->request = $request;
$this->response = $response;
@ -59,6 +61,7 @@ class Container {
$this->apiRoot = $apiRoot;
$this->editKey = $editKey;
$this->uploadKey = $uploadKey;
$this->accessKey = $accessKey;
}
public function getAuthProvider(): AuthProvider {
@ -156,4 +159,8 @@ class Container {
public function getUploadKey(): string {
return $this->uploadKey;
}
public function getAccessKey(): string {
return $this->accessKey;
}
}

View file

@ -34,8 +34,12 @@ class BaseController {
return $this->request->data[$name] ?? $default;
}
protected function getAccessKey(): string {
return Request::getHeader('ACCESS-KEY');
}
protected function getEditKey(): string {
$key = Request::getHeader('EDIT_KEY');
$key = Request::getHeader('EDIT-KEY');
if ($key) {
return $key;
}

View file

@ -28,7 +28,8 @@ class DemoController extends BaseController {
ChatProvider $chatProvider,
DemoListProvider $demoListProvider,
DemoStore $store,
string $editKey
string $editKey,
string $accessKey,
) {
parent::__construct($request, $response);
$this->demoProvider = $demoProvider;
@ -36,6 +37,11 @@ class DemoController extends BaseController {
$this->demoListProvider = $demoListProvider;
$this->store = $store;
$this->editKey = $editKey;
if ($this->getAccessKey() === $accessKey) {
$this->demoProvider->showPrivateData(true);
$this->demoListProvider->showPrivateData(true);
}
}
public function get(string $id): void {

View file

@ -8,6 +8,7 @@ use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Query\QueryBuilder;
class BaseProvider {
protected bool $showPrivateData = false;
protected Connection $connection;
/**
@ -30,4 +31,8 @@ class BaseProvider {
protected function getQueryBuilder() {
return new QueryBuilder($this->connection);
}
function showPrivateData(bool $show): void {
$this->showPrivateData = $show;
}
}

View file

@ -189,7 +189,9 @@ class DemoListProvider extends BaseProvider {
*/
protected function formatList(array $rows): array {
return array_map(function ($row) {
return Demo::fromRow($row);
$demo = Demo::fromRow($row);
$demo->showPrivateData($this->showPrivateData);
return $demo;
}, $rows);
}
}

View file

@ -43,6 +43,7 @@ class DemoProvider extends BaseProvider {
if (null === $demo) {
return null;
}
$demo->showPrivateData($this->showPrivateData);
if ($fetchDetails) {
$uploader = $this->userProvider->getById($demo->getUploader());

View file

@ -17,7 +17,8 @@ $demoController = new Controllers\DemoController(
$container->getChatProvider(),
$container->getDemoListProvider(),
$container->getDemoStore(),
$container->getEditKey()
$container->getEditKey(),
$container->getAccessKey()
);
$authController = new Controllers\AuthController(
$container->getRequest(),

View file

@ -60,6 +60,7 @@ $parserPath = getEnvVar('PARSER_PATH');
$appRoot = getEnvVar('APP_ROOT');
$editKey = getEnvVar('EDIT_SECRET');
$uploadKey = getEnvVar('UPLOAD_KEY');
$accessKey = getEnvVar('ACCESS_KEY');
$factory = new \RandomLib\Factory();
$generator = $factory->getMediumStrengthGenerator();
@ -75,7 +76,8 @@ $container = new Container(
$storeHost,
$appRoot,
$editKey,
$uploadKey
$uploadKey,
$accessKey,
);
return $container;