2020-05-16 17:14:17 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace OCA\BigBlueButton\BigBlueButton;
|
|
|
|
|
2022-05-23 12:41:42 +02:00
|
|
|
use OCA\DAV\Db\Direct;
|
|
|
|
use OCA\DAV\Db\DirectMapper;
|
|
|
|
use OCP\AppFramework\Utility\ITimeFactory;
|
2022-05-10 15:35:59 +02:00
|
|
|
use OCP\Files\IRootFolder;
|
|
|
|
use OCP\Files\File;
|
2022-05-23 12:41:42 +02:00
|
|
|
use OCP\Files\Folder;
|
2022-04-15 19:45:27 +02:00
|
|
|
use OCP\Files\Storage\IStorage;
|
2022-05-23 12:41:42 +02:00
|
|
|
use OCP\IURLGenerator;
|
|
|
|
use OCP\Security\ISecureRandom;
|
2022-04-15 19:45:27 +02:00
|
|
|
|
2022-05-10 15:35:59 +02:00
|
|
|
class Presentation
|
|
|
|
{
|
2020-05-16 17:14:17 +02:00
|
|
|
private $url;
|
2022-05-23 12:41:42 +02:00
|
|
|
private $userId;
|
2020-05-16 17:14:17 +02:00
|
|
|
|
2022-05-10 15:35:59 +02:00
|
|
|
/** @var File*/
|
|
|
|
private $file;
|
2020-05-16 17:14:17 +02:00
|
|
|
|
2022-05-23 12:41:42 +02:00
|
|
|
/** @var Folder */
|
2022-05-10 15:35:59 +02:00
|
|
|
private $userFolder;
|
2022-04-15 19:45:27 +02:00
|
|
|
|
2022-05-23 12:41:42 +02:00
|
|
|
/** @var DirectMapper */
|
|
|
|
private $mapper;
|
2022-04-15 19:45:27 +02:00
|
|
|
|
2022-05-23 12:41:42 +02:00
|
|
|
/** @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;
|
2022-04-15 19:45:27 +02:00
|
|
|
}
|
|
|
|
|
2022-05-23 12:41:42 +02:00
|
|
|
public function generateUrl()
|
2022-05-10 15:35:59 +02:00
|
|
|
{
|
2022-05-23 12:41:42 +02:00
|
|
|
$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);
|
|
|
|
|
2022-05-10 15:35:59 +02:00
|
|
|
return $url;
|
2020-05-16 17:14:17 +02:00
|
|
|
}
|
|
|
|
|
2022-05-10 15:35:59 +02:00
|
|
|
public function getUrl(): string
|
|
|
|
{
|
2020-05-16 17:14:17 +02:00
|
|
|
return $this->url;
|
|
|
|
}
|
|
|
|
|
2022-05-10 15:35:59 +02:00
|
|
|
public function getFilename(): string
|
|
|
|
{
|
|
|
|
return $this->file->getName();
|
2020-05-16 17:14:17 +02:00
|
|
|
}
|
|
|
|
|
2022-05-10 15:35:59 +02:00
|
|
|
public function isValid(): bool
|
|
|
|
{
|
|
|
|
return !empty($this->file->getContent());
|
2020-05-16 17:14:17 +02:00
|
|
|
}
|
|
|
|
}
|