|
|
|
|
@ -25,26 +25,32 @@ namespace OCA\Files\Collaboration\Resources; |
|
|
|
|
|
|
|
|
|
use OCP\Collaboration\Resources\IProvider; |
|
|
|
|
use OCP\Collaboration\Resources\IResource; |
|
|
|
|
use OCP\Collaboration\Resources\ResourceException; |
|
|
|
|
use OCP\Files\IRootFolder; |
|
|
|
|
use OCP\Files\Node; |
|
|
|
|
use OCP\IPreview; |
|
|
|
|
use OCP\IURLGenerator; |
|
|
|
|
use OCP\IUser; |
|
|
|
|
|
|
|
|
|
class ResourceProvider implements IProvider { |
|
|
|
|
|
|
|
|
|
const RESOURCE_TYPE = 'files'; |
|
|
|
|
public const RESOURCE_TYPE = 'file'; |
|
|
|
|
|
|
|
|
|
/** @var IRootFolder */ |
|
|
|
|
protected $rootFolder; |
|
|
|
|
|
|
|
|
|
/** @var IPreview */ |
|
|
|
|
private $preview; |
|
|
|
|
/** @var IURLGenerator */ |
|
|
|
|
private $urlGenerator; |
|
|
|
|
|
|
|
|
|
/** @var array */ |
|
|
|
|
protected $nodes = []; |
|
|
|
|
|
|
|
|
|
public function __construct(IRootFolder $rootFolder, IURLGenerator $urlGenerator) { |
|
|
|
|
public function __construct(IRootFolder $rootFolder, |
|
|
|
|
IPreview $preview, |
|
|
|
|
IURLGenerator $urlGenerator) { |
|
|
|
|
$this->rootFolder = $rootFolder; |
|
|
|
|
$this->preview = $preview; |
|
|
|
|
$this->urlGenerator = $urlGenerator; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -61,21 +67,34 @@ class ResourceProvider implements IProvider { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Get the display name of a resource |
|
|
|
|
* |
|
|
|
|
* @param IResource $resource |
|
|
|
|
* @return string |
|
|
|
|
* @return array |
|
|
|
|
* @since 16.0.0 |
|
|
|
|
*/ |
|
|
|
|
public function getName(IResource $resource): string { |
|
|
|
|
public function getResourceRichObject(IResource $resource): array { |
|
|
|
|
if (isset($this->nodes[(int) $resource->getId()])) { |
|
|
|
|
return $this->nodes[(int) $resource->getId()]->getPath(); |
|
|
|
|
$node = $this->nodes[(int) $resource->getId()]->getPath(); |
|
|
|
|
} else { |
|
|
|
|
$node = $this->getNode($resource); |
|
|
|
|
} |
|
|
|
|
$node = $this->getNode($resource); |
|
|
|
|
if ($node) { |
|
|
|
|
return $node->getName(); |
|
|
|
|
|
|
|
|
|
if ($node instanceof Node) { |
|
|
|
|
$link = $this->urlGenerator->linkToRouteAbsolute( |
|
|
|
|
'files.viewcontroller.showFile', |
|
|
|
|
['fileid' => $resource->getId()] |
|
|
|
|
); |
|
|
|
|
return [ |
|
|
|
|
'type' => 'file', |
|
|
|
|
'id' => $resource->getId(), |
|
|
|
|
'name' => $node->getName(), |
|
|
|
|
'path' => $node->getInternalPath(), |
|
|
|
|
'link' => $link, |
|
|
|
|
'mimetype' => $node->getMimetype(), |
|
|
|
|
'preview-available' => $this->preview->isAvailable($node), |
|
|
|
|
]; |
|
|
|
|
} |
|
|
|
|
return ''; |
|
|
|
|
|
|
|
|
|
throw new ResourceException('File not found'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -102,25 +121,6 @@ class ResourceProvider implements IProvider { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Get the icon class of a resource |
|
|
|
|
* |
|
|
|
|
* @param IResource $resource |
|
|
|
|
* @return string |
|
|
|
|
* @since 16.0.0 |
|
|
|
|
*/ |
|
|
|
|
public function getIconLink(IResource $resource): string { |
|
|
|
|
$node = $this->getNode($resource); |
|
|
|
|
if ($node && $node->getMimetype() === 'httpd/unix-directory') { |
|
|
|
|
return $this->urlGenerator->getAbsoluteURL( |
|
|
|
|
$this->urlGenerator->imagePath('core', 'places/files') |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
return $this->urlGenerator->getAbsoluteURL( |
|
|
|
|
$this->urlGenerator->imagePath('core', 'filetypes/file') |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Get the resource type of the provider |
|
|
|
|
* |
|
|
|
|
@ -130,15 +130,4 @@ class ResourceProvider implements IProvider { |
|
|
|
|
public function getType(): string { |
|
|
|
|
return self::RESOURCE_TYPE; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Get the link to a resource |
|
|
|
|
* |
|
|
|
|
* @param IResource $resource |
|
|
|
|
* @return string |
|
|
|
|
* @since 16.0.0 |
|
|
|
|
*/ |
|
|
|
|
public function getLink(IResource $resource): string { |
|
|
|
|
return $this->urlGenerator->linkToRoute('files.viewcontroller.showFile', ['fileid' => $resource->getId()]); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|