]> source.dussan.org Git - nextcloud-server.git/commitdiff
extend API to get the shares from all files in a given folder
authorBjoern Schiessle <schiessle@owncloud.com>
Thu, 19 Sep 2013 14:41:29 +0000 (16:41 +0200)
committerBjoern Schiessle <schiessle@owncloud.com>
Thu, 19 Sep 2013 14:41:29 +0000 (16:41 +0200)
apps/files_sharing/lib/api.php

index 8ed9b4e2345bf42e7cbe5cc5bf3262af1497af1b..06da492ba155eae7db0feccb0eeda180fdbdbdd8 100644 (file)
@@ -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