1
0
Fork 0
mirror of https://github.com/Yetangitu/owncloud-apps.git synced 2025-10-02 14:49:17 +02:00

files_reader: #40, but this time for real: detect shared folder/file and get fileid for such when applicable

This commit is contained in:
frankdelange 2017-03-29 20:23:42 +02:00
parent 2afaf05106
commit d268ebb098

View file

@ -17,6 +17,8 @@ use OCP\IRequest;
use OCP\IURLGenerator; use OCP\IURLGenerator;
use OCP\Files\IRootFolder; use OCP\Files\IRootFolder;
use OCP\Share\IManager; use OCP\Share\IManager;
use OCP\Files\FileInfo;
use OCP\Files\NotFoundException;
use OCA\Files_Reader\Service\BookmarkService; use OCA\Files_Reader\Service\BookmarkService;
use OCA\Files_Reader\Service\MetadataService; use OCA\Files_Reader\Service\MetadataService;
@ -124,15 +126,32 @@ class PageController extends Controller {
* @brief sharing-aware file info retriever * @brief sharing-aware file info retriever
* *
* Work around the differences between normal and shared file access * Work around the differences between normal and shared file access
* (this should be abstracted away in OC/NC IMnsHO)
* *
* @param string $path path-fragment from url * @param string $path path-fragment from url
* @return array * @return array
* @throws NotFoundException
*/ */
private function getFileInfo($path) { private function getFileInfo($path) {
$count = 0; $count = 0;
$shareToken = preg_replace("/(?:\/index\.php)?\/s\/([A-Za-z0-9]{15})\/download/", "$1", $path, 1,$count); $shareToken = preg_replace("/(?:\/index\.php)?\/s\/([A-Za-z0-9]{15})\/download.*/", "$1", $path, 1,$count);
if ($count === 1) { if ($count === 1) {
/* shared file or directory */
$node = $this->shareManager->getShareByToken($shareToken)->getNode(); $node = $this->shareManager->getShareByToken($shareToken)->getNode();
$type = $node->getType();
/* shared directory, need file path to continue, */
if ($type == \OCP\Files\FileInfo::TYPE_FOLDER) {
$query = [];
parse_str(parse_url($path, PHP_URL_QUERY), $query);
if (isset($query['path']) && isset($query['files'])) {
$node = $node->get($query['path'])->get($query['files']);
} else {
throw new NotFoundException('Shared file path or name not set');
}
}
$filePath = $node->getPath(); $filePath = $node->getPath();
$fileId = $node->getId(); $fileId = $node->getId();
} else { } else {