From c9f1538c1f5d9f950da77c869d16b3dfec8e46d8 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Thu, 19 Sep 2013 16:41:29 +0200 Subject: [PATCH] extend API to get the shares from all files in a given folder --- apps/files_sharing/lib/api.php | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/apps/files_sharing/lib/api.php b/apps/files_sharing/lib/api.php index 8ed9b4e2345..06da492ba15 100644 --- a/apps/files_sharing/lib/api.php +++ b/apps/files_sharing/lib/api.php @@ -35,6 +35,11 @@ class Api { // if a file is specified, get the share for this file if (isset($_GET['file'])) { $params['itemSource'] = self::getFileId($_GET['file']); + $params['path'] = $_GET['file']; + if (isset($_GET['subfiles']) && $_GET['subfiles'] === 'yes') { + error_log("get shares from folder"); + return self::getSharesFromFolder($params); + } return self::getShare($params); } @@ -88,6 +93,33 @@ class Api { } } + /** + * @brief get share from all files in a given folder (non-recursive) + * @param array $params contains 'path' to the folder + * @return \OC_OCS_Result + */ + private static function getSharesFromFolder($params) { + $path = $params['path']; + $view = new \OC\Files\View('/'.\OCP\User::getUser().'/files'); + + if(!$view->is_dir($path)) { + return new \OC_OCS_Result(null, 404, "not a directory"); + } + + $content = $view->getDirectoryContent($path); + + $result = array(); + foreach ($content as $file) { + $share = \OCP\Share::getItemShared('file', $file['fileid']); + if ($share) { + $share['filename'] = $file['name']; + $result[] = $share; + } + } + + return new \OC_OCS_Result($result); + } + /** * @breif create a new share * @param array $params -- 2.39.5