Rewrite old preview endpoint for PreviewManager
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
parent
9dbcc1a177
commit
9bbfb5ffeb
|
@ -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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -124,7 +124,8 @@ class Server extends ServerContainer implements IServerContainer {
|
|||
$c->getConfig(),
|
||||
$c->getRootFolder(),
|
||||
$c->getAppDataDir('preview'),
|
||||
$c->getEventDispatcher()
|
||||
$c->getEventDispatcher(),
|
||||
$c->getSession()->get('user_id')
|
||||
);
|
||||
});
|
||||
|
||||
|
|
|
@ -86,7 +86,7 @@ interface IPreview {
|
|||
* @param boolean $scaleUp Scale smaller images up to the thumbnail size or not. Might look ugly
|
||||
* @return \OCP\IImage
|
||||
* @since 6.0.0
|
||||
* @deprecated 9.2.0 Use getPreview
|
||||
* @deprecated 11 Use getPreview
|
||||
*/
|
||||
public function createPreview($file, $maxX = 100, $maxY = 75, $scaleUp = false);
|
||||
|
||||
|
|
Loading…
Reference in New Issue