diff options
author | Roeland Jago Douma <roeland@famdouma.nl> | 2017-01-04 16:51:44 +0100 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2017-01-04 16:51:44 +0100 |
commit | 9bbfb5ffebf50e936b185e4e8dfea0b3c4449de5 (patch) | |
tree | c054d941f8aba2ea59ba44b2deecd4016c290575 /lib/private/PreviewManager.php | |
parent | 9dbcc1a177ea490d20c49186a8f8090342ecb5a9 (diff) | |
download | nextcloud-server-9bbfb5ffebf50e936b185e4e8dfea0b3c4449de5.tar.gz nextcloud-server-9bbfb5ffebf50e936b185e4e8dfea0b3c4449de5.zip |
Rewrite old preview endpoint for PreviewManager
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'lib/private/PreviewManager.php')
-rw-r--r-- | lib/private/PreviewManager.php | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/lib/private/PreviewManager.php b/lib/private/PreviewManager.php index 36b3730a720..8c5a7ad29f1 100644 --- a/lib/private/PreviewManager.php +++ b/lib/private/PreviewManager.php @@ -68,6 +68,9 @@ class PreviewManager implements IPreview { /** @var array */ protected $defaultProviders; + /** @var string */ + protected $userId; + /** * PreviewManager constructor. * @@ -75,15 +78,18 @@ class PreviewManager implements IPreview { * @param IRootFolder $rootFolder * @param IAppData $appData * @param EventDispatcherInterface $eventDispatcher + * @param string $userId */ public function __construct(IConfig $config, IRootFolder $rootFolder, IAppData $appData, - EventDispatcherInterface $eventDispatcher) { + EventDispatcherInterface $eventDispatcher, + $userId) { $this->config = $config; $this->rootFolder = $rootFolder; $this->appData = $appData; $this->eventDispatcher = $eventDispatcher; + $this->userId = $userId; } /** @@ -144,10 +150,22 @@ class PreviewManager implements IPreview { * @param int $maxY The maximum Y size of the thumbnail. It can be smaller depending on the shape of the image * @param boolean $scaleUp Scale smaller images up to the thumbnail size or not. Might look ugly * @return \OCP\IImage + * @deprecated 11 Use getPreview */ public function createPreview($file, $maxX = 100, $maxY = 75, $scaleUp = false) { - $preview = new \OC\Preview('', '/', $file, $maxX, $maxY, $scaleUp); - return $preview->getPreview(); + try { + $userRoot = $this->rootFolder->getUserFolder($this->userId)->getParent(); + $node = $userRoot->get($file); + if (!($file instanceof File)) { + throw new NotFoundException(); + } + + $preview = $this->getPreview($node, $maxX, $maxY); + } catch (\Exception $e) { + return new \OC_Image(); + } + + return new \OC_Image($preview->getContent()); } /** |