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

allow sending edit key as header

This commit is contained in:
Robin Appelman 2025-05-03 15:33:10 +02:00
commit 1593435254
2 changed files with 9 additions and 1 deletions

View file

@ -34,6 +34,14 @@ class BaseController {
return $this->request->data[$name] ?? $default; return $this->request->data[$name] ?? $default;
} }
protected function getEditKey(): string {
$key = Request::getHeader('EDIT_KEY');
if ($key) {
return $key;
}
return $this->post('key', '');
}
protected function json( protected function json(
mixed $data, mixed $data,
int $code = 200, int $code = 200,

View file

@ -147,7 +147,7 @@ class DemoController extends BaseController {
$backend = $this->post('backend', ''); $backend = $this->post('backend', '');
$path = $this->post('path', ''); $path = $this->post('path', '');
$url = $this->post('url', ''); $url = $this->post('url', '');
$editKey = $this->post('key', ''); $editKey = $this->getEditKey();
if ($editKey !== $this->editKey || '' === $editKey) { if ($editKey !== $this->editKey || '' === $editKey) {
throw new InvalidKeyException('Invalid key'); throw new InvalidKeyException('Invalid key');
} }