diff options
-rw-r--r-- | apps/files_sharing/ajax/external.php | 9 | ||||
-rw-r--r-- | apps/files_sharing/ajax/shareinfo.php | 62 | ||||
-rw-r--r-- | apps/files_sharing/lib/external/scanner.php | 52 | ||||
-rw-r--r-- | apps/files_sharing/lib/external/storage.php | 25 |
4 files changed, 147 insertions, 1 deletions
diff --git a/apps/files_sharing/ajax/external.php b/apps/files_sharing/ajax/external.php index e7bf903f705..c25b34ab552 100644 --- a/apps/files_sharing/ajax/external.php +++ b/apps/files_sharing/ajax/external.php @@ -23,6 +23,13 @@ $externalManager = new \OCA\Files_Sharing\External\Manager( ); $mount = $externalManager->addShare($remote, $token, $password, $name, $owner); -$result = $mount->getStorage()->file_exists(''); +/** + * @var \OCA\Files_Sharing\External\Storage $storage + */ +$storage = $mount->getStorage(); +$result = $storage->file_exists(''); +if($result){ + $storage->getScanner()->scanAll(); +} echo json_encode($result); diff --git a/apps/files_sharing/ajax/shareinfo.php b/apps/files_sharing/ajax/shareinfo.php new file mode 100644 index 00000000000..4aefdbe7b15 --- /dev/null +++ b/apps/files_sharing/ajax/shareinfo.php @@ -0,0 +1,62 @@ +<?php +/** + * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +if (!\OC_App::isEnabled('files_sharing')) { + exit; +} + +if (!isset($_GET['t'])) { + \OC_Response::setStatus(400); //400 Bad Request + exit; +} + +$token = $_GET['t']; + +$password = null; +if (isset($_POST['password'])) { + $password = $_POST['password']; +} + +$relativePath = null; +if (isset($_GET['dir'])) { + $relativePath = $_GET['dir']; +} + +$data = \OCA\Files_Sharing\Helper::setupFromToken($token, $relativePath, $password); + +$linkItem = $data['linkItem']; +// Load the files +$path = $data['realPath']; + +$rootInfo = \OC\Files\Filesystem::getFileInfo($path); +$rootView = new \OC\Files\View(''); + +/** + * @param \OCP\Files\FileInfo $dir + * @param \OC\Files\View $view + * @return array + */ +function getChildInfo($dir, $view) { + $children = $view->getDirectoryContent($dir->getPath()); + $result = array(); + foreach ($children as $child) { + $formated = \OCA\Files\Helper::formatFileInfo($child); + if ($child->getType() === 'dir') { + $formated['children'] = getChildInfo($child, $view); + } + $result[] = $formated; + } + return $result; +} + +$result = \OCA\Files\Helper::formatFileInfo($rootInfo); +if ($rootInfo->getType() === 'dir') { + $result['children'] = getChildInfo($rootInfo, $rootView); +} + +OCP\JSON::success(array('data' => $result)); diff --git a/apps/files_sharing/lib/external/scanner.php b/apps/files_sharing/lib/external/scanner.php new file mode 100644 index 00000000000..1f32d79b149 --- /dev/null +++ b/apps/files_sharing/lib/external/scanner.php @@ -0,0 +1,52 @@ +<?php +/** + * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OCA\Files_Sharing\External; + +class Scanner extends \OC\Files\Cache\Scanner { + /** + * @var \OCA\Files_Sharing\External\Storage + */ + protected $storage; + + public function scanAll() { + $remote = $this->storage->getRemote(); + $token = $this->storage->getToken(); + $password = $this->storage->getPassword(); + $url = $remote . '/index.php/apps/files_sharing/shareinfo?t=' . $token; + + $ch = curl_init(); + + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_POST, 1); + if ($password) { + curl_setopt($ch, CURLOPT_POSTFIELDS, + http_build_query(array('password' => $password))); + } + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + + $result = curl_exec($ch); + curl_close($ch); + + $data = json_decode($result, true); + if ($data['status'] === 'success') { + $this->addResult($data['data'], ''); + } else { + throw new \Exception('Error while scanning remote share'); + } + } + + private function addResult($data, $path) { + $this->cache->put($path, $data); + if ($data['children']) { + foreach ($data['children'] as $child) { + $this->addResult($child, ltrim($path . '/' . $child['name'], '/')); + } + } + } +} diff --git a/apps/files_sharing/lib/external/storage.php b/apps/files_sharing/lib/external/storage.php index 0e799a0e9e3..741e219eff7 100644 --- a/apps/files_sharing/lib/external/storage.php +++ b/apps/files_sharing/lib/external/storage.php @@ -28,6 +28,11 @@ class Storage extends \OC\Files\Storage\DAV implements ISharedStorage { private $mountPoint; /** + * @var string + */ + private $token; + + /** * @var \OCA\Files_Sharing\External\Manager */ private $manager; @@ -41,6 +46,7 @@ class Storage extends \OC\Files\Storage\DAV implements ISharedStorage { $secure = $protocol === 'https'; $root .= '/public.php/webdav'; $this->mountPoint = $options['mountpoint']; + $this->token = $options['token']; parent::__construct(array( 'secure' => $secure, 'host' => $host, @@ -62,6 +68,14 @@ class Storage extends \OC\Files\Storage\DAV implements ISharedStorage { return $this->mountPoint; } + public function getToken() { + return $this->token; + } + + public function getPassword() { + return $this->password; + } + /** * @brief get id of the mount point * @return string @@ -77,6 +91,17 @@ class Storage extends \OC\Files\Storage\DAV implements ISharedStorage { return $this->cache; } + /** + * @param string $path + * @return \OCA\Files_Sharing\External\Scanner + */ + public function getScanner($path = '') { + if (!isset($this->scanner)) { + $this->scanner = new Scanner($this); + } + return $this->scanner; + } + public function rename($path1, $path2) { // if we renamed the mount point we need to adjust the mountpoint in the database if (Filesystem::normalizePath($this->mountPoint) === Filesystem::normalizePath($path1)) { |