diff options
Diffstat (limited to 'apps/files_sharing/api/remote.php')
-rw-r--r-- | apps/files_sharing/api/remote.php | 101 |
1 files changed, 99 insertions, 2 deletions
diff --git a/apps/files_sharing/api/remote.php b/apps/files_sharing/api/remote.php index 0f6d2dc265a..76f9babcd19 100644 --- a/apps/files_sharing/api/remote.php +++ b/apps/files_sharing/api/remote.php @@ -27,9 +27,9 @@ use OCA\Files_Sharing\External\Manager; class Remote { /** - * Accept a remote share + * Get list of pending remote shares * - * @param array $params contains the shareID 'id' which should be accepted + * @param array $params empty * @return \OC_OCS_Result */ public static function getOpenShares($params) { @@ -90,4 +90,101 @@ class Remote { return new \OC_OCS_Result(null, 404, "wrong share ID, share doesn't exist."); } + + /** + * @param array $share Share with info from the share_external table + * @return enriched share info with data from the filecache + */ + private static function extendShareInfo($share) { + $view = new \OC\Files\View('/' . \OC_User::getUser() . '/files/'); + $info = $view->getFileInfo($shares['mountpoint']); + + $share['mimetype'] = $info->getMimetype(); + $share['mtime'] = $info->getMtime(); + $share['permissions'] = $info->getPermissions(); + $share['type'] = $info->getType(); + $share['file_id'] = $info->getId(); + + return $share; + } + + /** + * List accepted remote shares + * + * @param array $params + * @return \OC_OCS_Result + */ + public static function getShares($params) { + $externalManager = new Manager( + \OC::$server->getDatabaseConnection(), + Filesystem::getMountManager(), + Filesystem::getLoader(), + \OC::$server->getHTTPHelper(), + \OC::$server->getNotificationManager(), + \OC_User::getUser() + ); + + $shares = $externalManager->getAcceptedShares(); + + $shares = array_map('self::extendShareInfo', $shares); + + return new \OC_OCS_Result($shares); + } + + /** + * Get info of a remote share + * + * @param array $params contains the shareID 'id' + * @return \OC_OCS_Result + */ + public static function getShare($params) { + $externalManager = new Manager( + \OC::$server->getDatabaseConnection(), + Filesystem::getMountManager(), + Filesystem::getLoader(), + \OC::$server->getHTTPHelper(), + \OC::$server->getNotificationManager(), + \OC_User::getUser() + ); + + $shareInfo = $externalManager->getShare($params['id']); + + if ($shareInfo === false) { + return new \OC_OCS_Result(null, 404, 'share does not exist'); + } else { + $shareInfo = self::extendShareInfo($shareInfo); + return new \OC_OCS_Result($shareInfo); + } + } + + /** + * Unshare a remote share + * + * @param array $params contains the shareID 'id' which should be unshared + * @return \OC_OCS_Result + */ + public static function unshare($params) { + $externalManager = new Manager( + \OC::$server->getDatabaseConnection(), + Filesystem::getMountManager(), + Filesystem::getLoader(), + \OC::$server->getHTTPHelper(), + \OC::$server->getNotificationManager(), + \OC_User::getUser() + ); + + $shareInfo = $externalManager->getShare($params['id']); + + if ($shareInfo === false) { + return new \OC_OCS_Result(null, 404, 'Share does not exist'); + } + + $mountPoint = '/' . \OC_User::getUser() . '/files' . $shareInfo['mountpoint']; + + if ($externalManager->removeShare($mountPoint) === true) { + return new \OC_OCS_Result(null); + } else { + return new \OC_OCS_Result(null, 403, 'Could not unshare'); + } + } } |