diff --git a/lib/BigBlueButton/Presentation.php b/lib/BigBlueButton/Presentation.php index b473def..1efaaa0 100644 --- a/lib/BigBlueButton/Presentation.php +++ b/lib/BigBlueButton/Presentation.php @@ -2,37 +2,49 @@ namespace OCA\BigBlueButton\BigBlueButton; +use OCP\Files\IRootFolder; +use OCP\Files\File; use OCP\Files\Storage\IStorage; -class Presentation { +class Presentation +{ private $url; - private $filename; + /** @var File*/ + private $file; - private $path; + /** @var IRootFolder */ + private $userFolder; /** @var IStorage */ private $storage; - public function __construct(string $path, IStorage $storage) { - $this->storage = $storage; - $this->path = preg_replace('/^\//', '', $path); - $this->filename = preg_replace('/[^\x20-\x7E]+/','#', $path); + public function __construct(string $path, string $userID, IRootFolder $iRootFolder) + { + $userFolder = $iRootFolder->getUserFolder($userID); + $this->file = $userFolder->get($path); + $this->storage = $this->file->getStorage(); } - public function generateUrl(): string { - return $this->storage->getDirectDownload($this->path); + public function generateUrl(): string + { + $filePath = $this->file->getInternalPath(); + [$url] = $this->storage->getDirectDownload($filePath); + return $url; } - public function getUrl(): string { + public function getUrl(): string + { return $this->url; } - public function getFilename(): string { - return $this->filename; + public function getFilename(): string + { + return $this->file->getName(); } - public function isValid(): bool { - return !empty($this->filename); + public function isValid(): bool + { + return !empty($this->file->getContent()); } } diff --git a/lib/Controller/JoinController.php b/lib/Controller/JoinController.php index 4e5387d..6115e29 100644 --- a/lib/Controller/JoinController.php +++ b/lib/Controller/JoinController.php @@ -14,7 +14,7 @@ use OCP\AppFramework\Controller; use OCP\AppFramework\Http\RedirectResponse; use OCP\AppFramework\Http\TemplateResponse; use OCP\BackgroundJob\IJobList; -use OCP\Files\Storage\IStorage; +use OCP\Files\IRootFolder; use OCP\IRequest; use OCP\IURLGenerator; use OCP\IUserSession; @@ -45,8 +45,8 @@ class JoinController extends Controller /** @var IJobList */ private $jobList; - /** @var IStorage */ - private $storage; + /** @var IRootFolder */ + private $iRootFolder; public function __construct( string $appName, @@ -57,7 +57,7 @@ class JoinController extends Controller API $api, Permission $permission, IJobList $jobList, - IStorage $storage + IRootFolder $iRootFolder ) { parent::__construct($appName, $request); @@ -67,7 +67,7 @@ class JoinController extends Controller $this->api = $api; $this->permission = $permission; $this->jobList = $jobList; - $this->storage = $storage; + $this->iRootFolder = $iRootFolder; } public function setToken(string $token): void @@ -117,13 +117,12 @@ class JoinController extends Controller throw new NoPermissionException(); } - if ($this->permission->isAdmin($room, $userId)) { - $presentation = new Presentation($filename, $this->storage); - } - - if (!$room->running && $presentation === null) { - $presentation = new Presentation($room->presentationPath, $this->storage); + if ($this->permission->isAdmin($room, $userId) && !empty($filename)) { + $presentation = new Presentation($filename, $userId, $this->iRootFolder); + } else if (!$room->running && !empty($room->presentationPath)) { + $presentation = new Presentation($room->presentationPath, $room->presentationUserId, $this->iRootFolder); } + } elseif ($room->access === Room::ACCESS_INTERNAL || $room->access === Room::ACCESS_INTERNAL_RESTRICTED) { return new RedirectResponse($this->getLoginUrl()); } elseif (empty($displayname) || strlen($displayname) < 3 || ($room->access === Room::ACCESS_PASSWORD && $password !== $room->password)) {