Move to AppData

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
Roeland Jago Douma 2016-10-07 14:16:38 +02:00
parent 958c1289b1
commit 743132650a
No known key found for this signature in database
GPG Key ID: 1E152838F164D13B
3 changed files with 34 additions and 38 deletions

View File

@ -30,7 +30,11 @@ $file = $userFolder->get($file);
$p = new \OC\Preview2(\OC::$server->getRootFolder(), $p = new \OC\Preview2(\OC::$server->getRootFolder(),
\OC::$server->getConfig(), \OC::$server->getConfig(),
\OC::$server->getPreviewManager(), \OC::$server->getPreviewManager(),
$file); $file,
\OC::$server->getAppDataDir('preview'));
$p->getPreview($maxX, $maxY, !$keepAspect, $mode); $image = $p->getPreview($maxX, $maxY, !$keepAspect, $mode);
header('Content-Type: ' . $image->getMimeType());
echo $image->getContent();

View File

@ -69,11 +69,11 @@ $this->create('search_ajax_search', '/core/search')
->actionInclude('core/search/ajax/search.php'); ->actionInclude('core/search/ajax/search.php');
// Routing // Routing
$this->create('core_ajax_preview', '/core/preview') $this->create('core_ajax_preview', '/core/preview')
->actionInclude('core/ajax/preview.php'); ->actionInclude('core/ajax/preview2.php');
$this->create('core_ajax_preview2', '/core/preview2') $this->create('core_ajax_preview2', '/core/preview2')
->actionInclude('core/ajax/preview2.php'); ->actionInclude('core/ajax/preview2.php');
$this->create('core_ajax_preview', '/core/preview.png') $this->create('core_ajax_preview', '/core/preview.png')
->actionInclude('core/ajax/preview.php'); ->actionInclude('core/ajax/preview2.php');
$this->create('core_ajax_update', '/core/ajax/update.php') $this->create('core_ajax_update', '/core/ajax/update.php')
->actionInclude('core/ajax/update.php'); ->actionInclude('core/ajax/update.php');

View File

@ -24,9 +24,11 @@ namespace OC;
use OC\Files\View; use OC\Files\View;
use OCP\Files\File; use OCP\Files\File;
use OCP\Files\Folder; use OCP\Files\IAppData;
use OCP\Files\IRootFolder; use OCP\Files\IRootFolder;
use OCP\Files\NotFoundException; use OCP\Files\NotFoundException;
use OCP\Files\SimpleFS\ISimpleFile;
use OCP\Files\SimpleFS\ISimpleFolder;
use OCP\IConfig; use OCP\IConfig;
use OCP\IImage; use OCP\IImage;
use OCP\Image; use OCP\Image;
@ -48,17 +50,21 @@ class Preview2 {
private $previewManager; private $previewManager;
/** @var IConfig */ /** @var IConfig */
private $config; private $config;
/** @var IAppData */
private $appData;
public function __construct( public function __construct(
IRootFolder $rootFolder, IRootFolder $rootFolder,
IConfig $config, IConfig $config,
IPreview $previewManager, IPreview $previewManager,
File $file File $file,
IAppData $appData
) { ) {
$this->rootFolder = $rootFolder; $this->rootFolder = $rootFolder;
$this->config = $config; $this->config = $config;
$this->file = $file; $this->file = $file;
$this->previewManager = $previewManager; $this->previewManager = $previewManager;
$this->appData = $appData;
} }
/** /**
@ -71,7 +77,7 @@ class Preview2 {
* @param int $height * @param int $height
* @param bool $crop * @param bool $crop
* @param string $mode * @param string $mode
* @return File * @return ISimpleFile
* @throws NotFoundException * @throws NotFoundException
*/ */
public function getPreview($width = -1, $height = -1, $crop = false, $mode = Preview2::MODE_FILL) { public function getPreview($width = -1, $height = -1, $crop = false, $mode = Preview2::MODE_FILL) {
@ -103,14 +109,13 @@ class Preview2 {
} }
/** /**
* @param Folder $previewFolder * @param ISimpleFolder $previewFolder
* @return File * @return ISimpleFile
* @throws NotFoundException * @throws NotFoundException
*/ */
private function getMaxPreview(Folder $previewFolder) { private function getMaxPreview(ISimpleFolder $previewFolder) {
$nodes = $previewFolder->getDirectoryListing(); $nodes = $previewFolder->getDirectoryListing();
/** @var File $node */
foreach ($nodes as $node) { foreach ($nodes as $node) {
if (strpos($node->getName(), 'max')) { if (strpos($node->getName(), 'max')) {
return $node; return $node;
@ -152,10 +157,10 @@ class Preview2 {
} }
/** /**
* @param File $file * @param ISimpleFile $file
* @return int[] * @return int[]
*/ */
private function getPreviewSize(File $file) { private function getPreviewSize(ISimpleFile $file) {
$size = explode('-', $file->getName()); $size = explode('-', $file->getName());
return [(int)$size[0], (int)$size[1]]; return [(int)$size[0], (int)$size[1]];
} }
@ -279,17 +284,17 @@ class Preview2 {
} }
/** /**
* @param Folder $previewFolder * @param ISimpleFolder $previewFolder
* @param File $maxPreview * @param ISimpleFile $maxPreview
* @param int $width * @param int $width
* @param int $height * @param int $height
* @param bool $crop * @param bool $crop
* @param int $maxWidth, * @param int $maxWidth,
* @param int $maxHeight * @param int $maxHeight
* @return File * @return ISimpleFile
* @throws NotFoundException * @throws NotFoundException
*/ */
private function generatePreview(Folder $previewFolder, File $maxPreview, $width, $height, $crop, $maxWidth, $maxHeight) { private function generatePreview(ISimpleFolder $previewFolder, ISimpleFile $maxPreview, $width, $height, $crop, $maxWidth, $maxHeight) {
$preview = new Image($maxPreview->getContent()); $preview = new Image($maxPreview->getContent());
if ($crop) { if ($crop) {
@ -322,45 +327,32 @@ class Preview2 {
} }
/** /**
* @param Folder $previewFolder * @param ISimpleFolder $previewFolder
* @param int $width * @param int $width
* @param int $height * @param int $height
* @param bool $crop * @param bool $crop
* @return File * @return ISimpleFile
* *
* @throws NotFoundException * @throws NotFoundException
*/ */
private function getCachedPreview(Folder $previewFolder, $width, $height, $crop) { private function getCachedPreview(ISimpleFolder $previewFolder, $width, $height, $crop) {
$path = $this->generatePath($width, $height, $crop); $path = $this->generatePath($width, $height, $crop);
return $previewFolder->get($path); return $previewFolder->getFile($path);
} }
/** /**
* Get the specific preview folder for this file * Get the specific preview folder for this file
* *
* @return Folder * @return ISimpleFolder
*/ */
private function getPreviewFolder() { private function getPreviewFolder() {
$user = $this->file->getOwner();
$user = $user->getUID();
$previewRoot = $this->rootFolder->getUserFolder($user);
$previewRoot = $previewRoot->getParent();
try { try {
/** @var Folder $previewRoot */ $folder = $this->appData->getFolder($this->file->getId());
$previewRoot = $previewRoot->get(self::THUMBNAILS_FOLDER);
} catch (NotFoundException $e) { } catch (NotFoundException $e) {
$previewRoot = $previewRoot->newFolder(self::THUMBNAILS_FOLDER); $folder = $this->appData->newFolder($this->file->getId());
} }
try { return $folder;
$previewFolder = $previewRoot->get($this->file->getId());
} catch (NotFoundException $e) {
$previewFolder = $previewRoot->newFolder($this->file->getId());
}
return $previewFolder;
} }
} }