feat: Default Presentation

generate direct in the DB instead of using getDirectDownload()
pull/207/head
Specht, David 2022-05-23 12:41:42 +02:00
parent 9f0f591d7a
commit 7f2372d207
2 changed files with 69 additions and 15 deletions

View File

@ -2,34 +2,71 @@
namespace OCA\BigBlueButton\BigBlueButton;
use OCA\DAV\Db\Direct;
use OCA\DAV\Db\DirectMapper;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Files\IRootFolder;
use OCP\Files\File;
use OCP\Files\Folder;
use OCP\Files\Storage\IStorage;
use OCP\IURLGenerator;
use OCP\Security\ISecureRandom;
class Presentation
{
private $url;
private $userId;
/** @var File*/
private $file;
/** @var IRootFolder */
/** @var Folder */
private $userFolder;
/** @var IStorage */
private $storage;
/** @var DirectMapper */
private $mapper;
public function __construct(string $path, string $userID, IRootFolder $iRootFolder)
{
$userFolder = $iRootFolder->getUserFolder($userID);
$this->file = $userFolder->get($path);
$this->storage = $this->file->getStorage();
/** @var ISecureRandom */
private $random;
/** @var ITimeFactory */
private $timeFactory;
/** @var IURLGenerator */
private $urlGenerator;
public function __construct(
string $path,
string $userId,
IRootFolder $iRootFolder,
DirectMapper $mapper,
ISecureRandom $random,
ITimeFactory $timeFactory,
IURLGenerator $urlGenerator
) {
$this->userFolder = $iRootFolder->getUserFolder($userId);
$this->file = $this->userFolder->get($path);
$this->mapper = $mapper;
$this->random = $random;
$this->timeFactory = $timeFactory;
$this->userId = $userId;
$this->urlGenerator = $urlGenerator;
}
public function generateUrl(): string
public function generateUrl()
{
$filePath = $this->file->getInternalPath();
[$url] = $this->storage->getDirectDownload($filePath);
$direct = new Direct();
$direct->setUserId($this->userId);
$direct->setFileId($this->file->getId());
$token = $this->random->generate(60, ISecureRandom::CHAR_ALPHANUMERIC);
$direct->setToken($token);
$direct->setExpiration($this->timeFactory->getTime() + (60 * 60 * 8));
$this->mapper->insert($direct);
$url = $this->urlGenerator->getAbsoluteURL('remote.php/direct/' . $token);
return $url;
}

View File

@ -10,14 +10,17 @@ use OCA\BigBlueButton\NoPermissionException;
use OCA\BigBlueButton\NotFoundException;
use OCA\BigBlueButton\Permission;
use OCA\BigBlueButton\Service\RoomService;
use OCA\DAV\Db\DirectMapper;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\RedirectResponse;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\IJobList;
use OCP\Files\IRootFolder;
use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\IUserSession;
use OCP\Security\ISecureRandom;
class JoinController extends Controller
{
@ -48,6 +51,15 @@ class JoinController extends Controller
/** @var IRootFolder */
private $iRootFolder;
/** @var DirectMapper */
private $mapper;
/** @var ISecureRandom */
private $random;
/** @var ITimeFactory */
private $timeFactory;
public function __construct(
string $appName,
IRequest $request,
@ -57,7 +69,10 @@ class JoinController extends Controller
API $api,
Permission $permission,
IJobList $jobList,
IRootFolder $iRootFolder
IRootFolder $iRootFolder,
DirectMapper $mapper,
ISecureRandom $random,
ITimeFactory $timeFactory
) {
parent::__construct($appName, $request);
@ -68,6 +83,9 @@ class JoinController extends Controller
$this->permission = $permission;
$this->jobList = $jobList;
$this->iRootFolder = $iRootFolder;
$this->mapper = $mapper;
$this->random = $random;
$this->timeFactory = $timeFactory;
}
public function setToken(string $token): void
@ -118,11 +136,10 @@ class JoinController extends Controller
}
if ($this->permission->isAdmin($room, $userId) && !empty($filename)) {
$presentation = new Presentation($filename, $userId, $this->iRootFolder);
$presentation = new Presentation($filename, $userId, $this->iRootFolder, $this->mapper, $this->random, $this->timeFactory, $this->urlGenerator);
} else if (!$room->running && !empty($room->presentationPath)) {
$presentation = new Presentation($room->presentationPath, $room->presentationUserId, $this->iRootFolder);
$presentation = new Presentation($room->presentationPath, $room->presentationUserId, $this->iRootFolder, $this->mapper, $this->random, $this->timeFactory, $this->urlGenerator);
}
} 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)) {