cloud_bbb/lib/BigBlueButton/Presentation.php

82 lines
1.7 KiB
PHP
Raw Normal View History

2020-05-16 17:14:17 +02:00
<?php
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\IURLGenerator;
use OCP\Security\ISecureRandom;
class Presentation {
2020-05-16 17:14:17 +02:00
private $url;
private $userId;
2020-05-16 17:14:17 +02:00
/** @var File*/
private $file;
2020-05-16 17:14:17 +02:00
/** @var Folder */
private $userFolder;
/** @var DirectMapper */
private $mapper;
/** @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() {
$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;
2020-05-16 17:14:17 +02:00
}
public function getUrl(): string {
2020-05-16 17:14:17 +02:00
return $this->url;
}
public function getFilename(): string {
return $this->file->getName();
2020-05-16 17:14:17 +02:00
}
public function isValid(): bool {
return !empty($this->file->getContent());
2020-05-16 17:14:17 +02:00
}
}