feat: Default Presentation

get the direct download from the php api instead of frontend
pull/207/head
Specht, David 2022-05-10 15:35:59 +02:00
parent 38da9bda60
commit 9f0f591d7a
2 changed files with 36 additions and 25 deletions

View File

@ -2,37 +2,49 @@
namespace OCA\BigBlueButton\BigBlueButton; namespace OCA\BigBlueButton\BigBlueButton;
use OCP\Files\IRootFolder;
use OCP\Files\File;
use OCP\Files\Storage\IStorage; use OCP\Files\Storage\IStorage;
class Presentation { class Presentation
{
private $url; private $url;
private $filename; /** @var File*/
private $file;
private $path; /** @var IRootFolder */
private $userFolder;
/** @var IStorage */ /** @var IStorage */
private $storage; private $storage;
public function __construct(string $path, IStorage $storage) { public function __construct(string $path, string $userID, IRootFolder $iRootFolder)
$this->storage = $storage; {
$this->path = preg_replace('/^\//', '', $path); $userFolder = $iRootFolder->getUserFolder($userID);
$this->filename = preg_replace('/[^\x20-\x7E]+/','#', $path); $this->file = $userFolder->get($path);
$this->storage = $this->file->getStorage();
} }
public function generateUrl(): string { public function generateUrl(): string
return $this->storage->getDirectDownload($this->path); {
$filePath = $this->file->getInternalPath();
[$url] = $this->storage->getDirectDownload($filePath);
return $url;
} }
public function getUrl(): string { public function getUrl(): string
{
return $this->url; return $this->url;
} }
public function getFilename(): string { public function getFilename(): string
return $this->filename; {
return $this->file->getName();
} }
public function isValid(): bool { public function isValid(): bool
return !empty($this->filename); {
return !empty($this->file->getContent());
} }
} }

View File

@ -14,7 +14,7 @@ use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\RedirectResponse; use OCP\AppFramework\Http\RedirectResponse;
use OCP\AppFramework\Http\TemplateResponse; use OCP\AppFramework\Http\TemplateResponse;
use OCP\BackgroundJob\IJobList; use OCP\BackgroundJob\IJobList;
use OCP\Files\Storage\IStorage; use OCP\Files\IRootFolder;
use OCP\IRequest; use OCP\IRequest;
use OCP\IURLGenerator; use OCP\IURLGenerator;
use OCP\IUserSession; use OCP\IUserSession;
@ -45,8 +45,8 @@ class JoinController extends Controller
/** @var IJobList */ /** @var IJobList */
private $jobList; private $jobList;
/** @var IStorage */ /** @var IRootFolder */
private $storage; private $iRootFolder;
public function __construct( public function __construct(
string $appName, string $appName,
@ -57,7 +57,7 @@ class JoinController extends Controller
API $api, API $api,
Permission $permission, Permission $permission,
IJobList $jobList, IJobList $jobList,
IStorage $storage IRootFolder $iRootFolder
) { ) {
parent::__construct($appName, $request); parent::__construct($appName, $request);
@ -67,7 +67,7 @@ class JoinController extends Controller
$this->api = $api; $this->api = $api;
$this->permission = $permission; $this->permission = $permission;
$this->jobList = $jobList; $this->jobList = $jobList;
$this->storage = $storage; $this->iRootFolder = $iRootFolder;
} }
public function setToken(string $token): void public function setToken(string $token): void
@ -117,13 +117,12 @@ class JoinController extends Controller
throw new NoPermissionException(); throw new NoPermissionException();
} }
if ($this->permission->isAdmin($room, $userId)) { if ($this->permission->isAdmin($room, $userId) && !empty($filename)) {
$presentation = new Presentation($filename, $this->storage); $presentation = new Presentation($filename, $userId, $this->iRootFolder);
} else if (!$room->running && !empty($room->presentationPath)) {
$presentation = new Presentation($room->presentationPath, $room->presentationUserId, $this->iRootFolder);
} }
if (!$room->running && $presentation === null) {
$presentation = new Presentation($room->presentationPath, $this->storage);
}
} elseif ($room->access === Room::ACCESS_INTERNAL || $room->access === Room::ACCESS_INTERNAL_RESTRICTED) { } elseif ($room->access === Room::ACCESS_INTERNAL || $room->access === Room::ACCESS_INTERNAL_RESTRICTED) {
return new RedirectResponse($this->getLoginUrl()); return new RedirectResponse($this->getLoginUrl());
} elseif (empty($displayname) || strlen($displayname) < 3 || ($room->access === Room::ACCESS_PASSWORD && $password !== $room->password)) { } elseif (empty($displayname) || strlen($displayname) < 3 || ($room->access === Room::ACCESS_PASSWORD && $password !== $room->password)) {