Rewrite old preview endpoint for PreviewManager

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
Roeland Jago Douma 2017-01-04 16:51:44 +01:00
parent 9dbcc1a177
commit 9bbfb5ffeb
No known key found for this signature in database
GPG Key ID: F941078878347C0C
3 changed files with 24 additions and 5 deletions

View File

@ -68,6 +68,9 @@ class PreviewManager implements IPreview {
/** @var array */ /** @var array */
protected $defaultProviders; protected $defaultProviders;
/** @var string */
protected $userId;
/** /**
* PreviewManager constructor. * PreviewManager constructor.
* *
@ -75,15 +78,18 @@ class PreviewManager implements IPreview {
* @param IRootFolder $rootFolder * @param IRootFolder $rootFolder
* @param IAppData $appData * @param IAppData $appData
* @param EventDispatcherInterface $eventDispatcher * @param EventDispatcherInterface $eventDispatcher
* @param string $userId
*/ */
public function __construct(IConfig $config, public function __construct(IConfig $config,
IRootFolder $rootFolder, IRootFolder $rootFolder,
IAppData $appData, IAppData $appData,
EventDispatcherInterface $eventDispatcher) { EventDispatcherInterface $eventDispatcher,
$userId) {
$this->config = $config; $this->config = $config;
$this->rootFolder = $rootFolder; $this->rootFolder = $rootFolder;
$this->appData = $appData; $this->appData = $appData;
$this->eventDispatcher = $eventDispatcher; $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 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 * @param boolean $scaleUp Scale smaller images up to the thumbnail size or not. Might look ugly
* @return \OCP\IImage * @return \OCP\IImage
* @deprecated 11 Use getPreview
*/ */
public function createPreview($file, $maxX = 100, $maxY = 75, $scaleUp = false) { public function createPreview($file, $maxX = 100, $maxY = 75, $scaleUp = false) {
$preview = new \OC\Preview('', '/', $file, $maxX, $maxY, $scaleUp); try {
return $preview->getPreview(); $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());
} }
/** /**

View File

@ -124,7 +124,8 @@ class Server extends ServerContainer implements IServerContainer {
$c->getConfig(), $c->getConfig(),
$c->getRootFolder(), $c->getRootFolder(),
$c->getAppDataDir('preview'), $c->getAppDataDir('preview'),
$c->getEventDispatcher() $c->getEventDispatcher(),
$c->getSession()->get('user_id')
); );
}); });

View File

@ -86,7 +86,7 @@ interface IPreview {
* @param boolean $scaleUp Scale smaller images up to the thumbnail size or not. Might look ugly * @param boolean $scaleUp Scale smaller images up to the thumbnail size or not. Might look ugly
* @return \OCP\IImage * @return \OCP\IImage
* @since 6.0.0 * @since 6.0.0
* @deprecated 9.2.0 Use getPreview * @deprecated 11 Use getPreview
*/ */
public function createPreview($file, $maxX = 100, $maxY = 75, $scaleUp = false); public function createPreview($file, $maxX = 100, $maxY = 75, $scaleUp = false);