Skip to content

Commit

Permalink
Allow the creationg of previews of files stored in appdata
Browse files Browse the repository at this point in the history
To allow us to create previews of files stored in appdata we need to
construct the view differently.

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
  • Loading branch information
rullzer committed Oct 8, 2018
1 parent 7971ba5 commit 34db505
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
22 changes: 16 additions & 6 deletions lib/private/Preview/GeneratorHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use OCP\Files\File;
use OCP\Files\IRootFolder;
use OCP\Files\SimpleFS\ISimpleFile;
use OCP\IConfig;
use OCP\IImage;
use OCP\Image as OCPImage;
use OCP\Preview\IProvider;
Expand All @@ -38,8 +39,12 @@ class GeneratorHelper {
/** @var IRootFolder */
private $rootFolder;

public function __construct(IRootFolder $rootFolder) {
/** @var IConfig */
private $config;

public function __construct(IRootFolder $rootFolder, IConfig $config) {
$this->rootFolder = $rootFolder;
$this->config = $config;
}

/**
Expand All @@ -63,13 +68,18 @@ private function getViewAndPath(File $file) {
$absPath = ltrim($file->getPath(), '/');
$owner = explode('/', $absPath)[0];

$userFolder = $this->rootFolder->getUserFolder($owner)->getParent();
if (strpos($owner, 'appdata_' . $this->config->getSystemValue('instanceid')) !== 0) {
$userFolder = $this->rootFolder->getUserFolder($owner)->getParent();

$nodes = $userFolder->getById($file->getId());
$file = $nodes[0];
$nodes = $userFolder->getById($file->getId());
$file = $nodes[0];

$view = new View($userFolder->getPath());
$path = $userFolder->getRelativePath($file->getPath());
$view = new View($userFolder->getPath());
$path = $userFolder->getRelativePath($file->getPath());
} else {
$view = new View($file->getParent()->getPath());
$path = $file->getName();
}

return [$view, $path];
}
Expand Down
3 changes: 2 additions & 1 deletion lib/private/PreviewManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ public function getPreview(File $file, $width = -1, $height = -1, $crop = false,
$this,
$this->appData,
new GeneratorHelper(
$this->rootFolder
$this->rootFolder,
$this->config
),
$this->eventDispatcher
);
Expand Down

0 comments on commit 34db505

Please sign in to comment.