diff options
author | Daniel Calviño Sánchez <danxuliu@gmail.com> | 2023-02-05 06:10:32 +0100 |
---|---|---|
committer | Daniel Calviño Sánchez <danxuliu@gmail.com> | 2023-02-14 10:37:19 +0100 |
commit | 4e0bf7360fb9775c5dca90032e5f33824eb5be09 (patch) | |
tree | baccc04bed2ef43d93445514c03fc4503199f12d /lib/Controller/RecordingController.php | |
parent | f1a6ab45adda6a83db2fcae683971f76f4ac6c94 (diff) |
Add verification for the recording server
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
Diffstat (limited to 'lib/Controller/RecordingController.php')
-rw-r--r-- | lib/Controller/RecordingController.php | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/Controller/RecordingController.php b/lib/Controller/RecordingController.php index d5ed53fa0..15b17b115 100644 --- a/lib/Controller/RecordingController.php +++ b/lib/Controller/RecordingController.php @@ -26,12 +26,14 @@ declare(strict_types=1); namespace OCA\Talk\Controller; use InvalidArgumentException; +use GuzzleHttp\Exception\ConnectException; use OCA\Talk\Config; use OCA\Talk\Exceptions\UnauthorizedException; use OCA\Talk\Service\RecordingService; use OCA\Talk\Service\SIPBridgeService; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; +use OCP\Http\Client\IClientService; use OCP\IRequest; class RecordingController extends AEnvironmentAwareController { @@ -40,11 +42,46 @@ class RecordingController extends AEnvironmentAwareController { IRequest $request, private Config $talkConfig, private SIPBridgeService $SIPBridgeService, + private IClientService $clientService, private RecordingService $recordingService ) { parent::__construct($appName, $request); } + public function getWelcomeMessage(int $serverId): DataResponse { + $recordingServers = $this->talkConfig->getRecordingServers(); + if (empty($recordingServers) || !isset($recordingServers[$serverId])) { + return new DataResponse([], Http::STATUS_NOT_FOUND); + } + + $url = rtrim($recordingServers[$serverId]['server'], '/'); + + $client = $this->clientService->newClient(); + try { + $response = $client->get($url . '/api/v1/welcome', [ + 'verify' => (bool) $recordingServers[$serverId]['verify'], + 'nextcloud' => [ + 'allow_local_address' => true, + ], + ]); + + $body = $response->getBody(); + $data = json_decode($body, true); + + if (!is_array($data)) { + return new DataResponse([ + 'error' => 'JSON_INVALID', + ], Http::STATUS_INTERNAL_SERVER_ERROR); + } + + return new DataResponse($data); + } catch (ConnectException $e) { + return new DataResponse(['error' => 'CAN_NOT_CONNECT'], Http::STATUS_INTERNAL_SERVER_ERROR); + } catch (\Exception $e) { + return new DataResponse(['error' => $e->getCode()], Http::STATUS_INTERNAL_SERVER_ERROR); + } + } + /** * @PublicPage * @RequireModeratorParticipant |