Skip to content

Commit

Permalink
feat: read only handler
Browse files Browse the repository at this point in the history
Signed-off-by: Hoang Pham <[email protected]>
  • Loading branch information
hweihwang committed Jun 18, 2024
1 parent 6606f6d commit c3fc74a
Showing 1 changed file with 3 additions and 24 deletions.
27 changes: 3 additions & 24 deletions lib/Controller/WhiteboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,8 @@ public function __construct(
#[NoCSRFRequired]
#[PublicPage]
public function update(int $fileId, array $data): DataResponse {
$authHeader = $this->request->getHeader('Authorization');

if (!$authHeader) {
return new DataResponse(['message' => 'Unauthorized'], Http::STATUS_UNAUTHORIZED);
}

[$jwt] = sscanf($authHeader, 'Bearer %s');

if (!$jwt) {
return new DataResponse(['message' => 'Unauthorized'], Http::STATUS_UNAUTHORIZED);
}

try {
$key = $this->config->getSystemValueString('jwt_secret_key');
$decoded = JWT::decode($jwt, new Key($key, 'HS256'));
$userId = $decoded->userid;
} catch (\Exception $e) {
return new DataResponse(['message' => 'Unauthorized'], Http::STATUS_UNAUTHORIZED);
}

$userFolder = $this->rootFolder->getUserFolder($userId);
$user = $this->userSession->getUser();
$userFolder = $this->rootFolder->getUserFolder($user?->getUID());
$file = $userFolder->getById($fileId)[0];

if (empty($data)) {
Expand Down Expand Up @@ -108,11 +89,9 @@ public function show(int $fileId): DataResponse {
$file = $userFolder->getById($fileId)[0];

$fileContent = $file->getContent();

if (empty($fileContent)) {
if ($fileContent === '') {
$fileContent = '{"elements":[],"scrollToContent":true}';
}

$data = json_decode($fileContent, true, 512, JSON_THROW_ON_ERROR);

return new DataResponse([
Expand Down

0 comments on commit c3fc74a

Please sign in to comment.