diff options
author | Vincent Petry <pvince81@owncloud.com> | 2014-11-18 18:53:45 +0100 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2014-12-15 12:10:54 +0100 |
commit | a5bb66f4a723bce5c5fbe919a48cd5133204ef62 (patch) | |
tree | b2e067bde8aaa1de6973adc7760fafb1e37e9084 /apps/files/controller/apicontroller.php | |
parent | c6be491a89a4eebe15bcb20f6e0b01f23a093761 (diff) | |
download | nextcloud-server-a5bb66f4a723bce5c5fbe919a48cd5133204ef62.tar.gz nextcloud-server-a5bb66f4a723bce5c5fbe919a48cd5133204ef62.zip |
Added favorites feature to the files app
Diffstat (limited to 'apps/files/controller/apicontroller.php')
-rw-r--r-- | apps/files/controller/apicontroller.php | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/apps/files/controller/apicontroller.php b/apps/files/controller/apicontroller.php index 89d24a5c47f..1990971438b 100644 --- a/apps/files/controller/apicontroller.php +++ b/apps/files/controller/apicontroller.php @@ -12,13 +12,16 @@ use OCP\AppFramework\Http; use OCP\AppFramework\Controller; use OCP\IRequest; use OCP\AppFramework\Http\JSONResponse; +use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\DownloadResponse; use OC\Preview; +use OCA\Files\Service\TagService; class ApiController extends Controller { - public function __construct($appName, IRequest $request){ + public function __construct($appName, IRequest $request, TagService $tagService){ parent::__construct($appName, $request); + $this->tagService = $tagService; } @@ -49,4 +52,50 @@ class ApiController extends Controller { } } + /** + * Updates the info of the specified file path + * The passed tags are absolute, which means they will + * replace the actual tag selection. + * + * @NoAdminRequired + * @CORS + * + * @param string $path path + * @param array $tags array of tags + */ + public function updateFileTags($path, $tags = null) { + $result = array(); + // if tags specified or empty array, update tags + if (!is_null($tags)) { + try { + $this->tagService->updateFileTags($path, $tags); + } catch (\OCP\Files\NotFoundException $e) { + return new DataResponse($e->getMessage(), Http::STATUS_NOT_FOUND); + } + $result['tags'] = $tags; + } + return new DataResponse($result, Http::STATUS_OK); + } + + /** + * Returns a list of all files tagged with the given tag. + * + * @NoAdminRequired + * @CORS + * + * @param array $tagName tag name to filter by + */ + public function getFilesByTag($tagName) { + $files = array(); + $fileInfos = $this->tagService->getFilesByTag($tagName); + foreach ($fileInfos as &$fileInfo) { + $file = \OCA\Files\Helper::formatFileInfo($fileInfo); + $parts = explode('/', dirname($fileInfo->getPath()), 4); + $file['path'] = '/' . $parts[3]; + $file['tags'] = array($tagName); + $files[] = $file; + } + return new DataResponse(array('files' => $files), Http::STATUS_OK); + } + } |