mirror of
https://codeberg.org/demostf/api.git
synced 2026-06-03 18:04:08 +02:00
add option to limit uploads to a single key
This commit is contained in:
parent
5b2896dc09
commit
96a9803e30
4 changed files with 68 additions and 12 deletions
|
|
@ -34,6 +34,7 @@ class Container {
|
|||
private $editKey;
|
||||
private $request;
|
||||
private $response;
|
||||
private $uploadKey;
|
||||
|
||||
public function __construct(
|
||||
Request $request,
|
||||
|
|
@ -45,7 +46,8 @@ class Container {
|
|||
string $storeRoot,
|
||||
string $storeUrl,
|
||||
string $apiRoot,
|
||||
string $editKey
|
||||
string $editKey,
|
||||
string $uploadKey
|
||||
) {
|
||||
$this->request = $request;
|
||||
$this->response = $response;
|
||||
|
|
@ -57,6 +59,7 @@ class Container {
|
|||
$this->storeUrl = $storeUrl;
|
||||
$this->apiRoot = $apiRoot;
|
||||
$this->editKey = $editKey;
|
||||
$this->uploadKey = $uploadKey;
|
||||
}
|
||||
|
||||
public function getAuthProvider(): AuthProvider {
|
||||
|
|
@ -102,7 +105,8 @@ class Container {
|
|||
$this->getChatProvider(),
|
||||
$this->getUserProvider(),
|
||||
$this->getDemoProvider()
|
||||
)
|
||||
),
|
||||
$this->getUploadKey()
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -149,4 +153,8 @@ class Container {
|
|||
public function getResponse(): Response {
|
||||
return $this->response;
|
||||
}
|
||||
|
||||
public function getUploadKey(): string {
|
||||
return $this->uploadKey;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,16 +30,18 @@ class UploadProvider extends BaseProvider {
|
|||
/** @var DemoSaver */
|
||||
private $demoSaver;
|
||||
private $baseUrl;
|
||||
private $uploadKey;
|
||||
|
||||
public function __construct(
|
||||
Connection $db,
|
||||
string $baseUrl,
|
||||
HeaderParser $headerParser,
|
||||
Parser $parser,
|
||||
DemoStore $store,
|
||||
UserProvider $userProvider,
|
||||
DemoProvider $demoProvider,
|
||||
DemoSaver $demoSaver
|
||||
string $baseUrl,
|
||||
HeaderParser $headerParser,
|
||||
Parser $parser,
|
||||
DemoStore $store,
|
||||
UserProvider $userProvider,
|
||||
DemoProvider $demoProvider,
|
||||
DemoSaver $demoSaver,
|
||||
string $uploadKey
|
||||
) {
|
||||
parent::__construct($db);
|
||||
$this->baseUrl = $baseUrl;
|
||||
|
|
@ -49,11 +51,12 @@ class UploadProvider extends BaseProvider {
|
|||
$this->userProvider = $userProvider;
|
||||
$this->demoProvider = $demoProvider;
|
||||
$this->demoSaver = $demoSaver;
|
||||
$this->uploadKey = $uploadKey;
|
||||
}
|
||||
|
||||
public function upload(string $key, string $red, string $blu, string $name, string $demoFile): string {
|
||||
$user = $this->userProvider->byKey($key);
|
||||
if (!$user) {
|
||||
if (!$user || ($this->uploadKey !== '' && $this->uploadKey !== $key)) {
|
||||
return 'Invalid key';
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ $storeHost = getenv('DEMO_HOST') ?: '';
|
|||
$parserUrl = getenv('PARSER_URL') ?: '';
|
||||
$appRoot = getenv('APP_ROOT') ?: '';
|
||||
$editKey = getenv('EDIT_SECRET') ?: '';
|
||||
$uploadKey = getenv('UPLOAD_KEY') ?: '';
|
||||
|
||||
$factory = new \RandomLib\Factory();
|
||||
$generator = $factory->getMediumStrengthGenerator();
|
||||
|
|
@ -42,7 +43,8 @@ $container = new Container(
|
|||
$storeRoot,
|
||||
$storeHost,
|
||||
$appRoot,
|
||||
$editKey
|
||||
$editKey,
|
||||
$uploadKey
|
||||
);
|
||||
|
||||
return $container;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue