diff options
author | Vitor Mattos <vitor@php.rio> | 2022-12-26 11:38:57 -0300 |
---|---|---|
committer | Vitor Mattos <vitor@php.rio> | 2022-12-26 11:38:57 -0300 |
commit | 94c14c08f7582e87736d97c536caaff1afd8a7cb (patch) | |
tree | 13bf97004eb3966ee0b1426c1633b7918fe0a871 /lib/Controller/RecordingController.php | |
parent | ec22f04af79679c3f51d0c0e3e0c5b10716665f5 (diff) |
Add route to store recortings
Signed-off-by: Vitor Mattos <vitor@php.rio>
Diffstat (limited to 'lib/Controller/RecordingController.php')
-rw-r--r-- | lib/Controller/RecordingController.php | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/Controller/RecordingController.php b/lib/Controller/RecordingController.php index 150fe464c..d8c4d1404 100644 --- a/lib/Controller/RecordingController.php +++ b/lib/Controller/RecordingController.php @@ -26,18 +26,28 @@ declare(strict_types=1); namespace OCA\Talk\Controller; use InvalidArgumentException; +use OCA\Talk\Config; +use OCA\Talk\Exceptions\UnauthorizedException; use OCA\Talk\Service\RoomService; +use OCA\Talk\Service\SIPBridgeService; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; use OCP\IRequest; class RecordingController extends AEnvironmentAwareController { + private Config $talkConfig; + private SIPBridgeService $SIPBridgeService; private RoomService $roomService; + public function __construct(string $appName, IRequest $request, + Config $talkConfig, + SIPBridgeService $SIPBridgeService, RoomService $roomService) { parent::__construct($appName, $request); + $this->talkConfig = $talkConfig; + $this->SIPBridgeService = $SIPBridgeService; $this->roomService = $roomService; } @@ -66,4 +76,34 @@ class RecordingController extends AEnvironmentAwareController { } return new DataResponse(); } + + /** + * @PublicPage + * @RequireRoom + * @BruteForceProtection(action=talkSipBridgeSecret) + * + * @return DataResponse + */ + public function store(string $owner): DataResponse { + try { + $random = $this->request->getHeader('TALK_SIPBRIDGE_RANDOM'); + $checksum = $this->request->getHeader('TALK_SIPBRIDGE_CHECKSUM'); + $secret = $this->talkConfig->getSIPSharedSecret(); + if (!$this->SIPBridgeService->validateSIPBridgeRequest($random, $checksum, $secret, $this->room->getToken())) { + throw new UnauthorizedException(); + } + } catch (UnauthorizedException $e) { + $response = new DataResponse([], Http::STATUS_UNAUTHORIZED); + $response->throttle(); + return $response; + } + + try { + $file = $this->request->getUploadedFile('file'); + $this->roomService->store($this->getRoom(), $owner, $file); + } catch (InvalidArgumentException $e) { + return new DataResponse(['error' => $e->getMessage()], Http::STATUS_BAD_REQUEST); + } + return new DataResponse(); + } } |