diff options
author | Robin Appelman <robin@icewind.nl> | 2016-07-22 14:48:51 +0200 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2016-07-22 14:48:51 +0200 |
commit | b94ff97a77be3947e62373cd4c6b75d7dfe5e5cc (patch) | |
tree | 48f1a424553f66d4f736d83bf25c4f0b6ff07dfa | |
parent | e321ecd592fef123772c6e61e175b6a34a3c5044 (diff) | |
download | nextcloud-server-b94ff97a77be3947e62373cd4c6b75d7dfe5e5cc.tar.gz nextcloud-server-b94ff97a77be3947e62373cd4c6b75d7dfe5e5cc.zip |
add recent files api endpoint
-rw-r--r-- | apps/files/appinfo/routes.php | 5 | ||||
-rw-r--r-- | apps/files/lib/AppInfo/Application.php | 3 | ||||
-rw-r--r-- | apps/files/lib/Controller/ApiController.php | 66 |
3 files changed, 56 insertions, 18 deletions
diff --git a/apps/files/appinfo/routes.php b/apps/files/appinfo/routes.php index 34bb1011773..7b5ac63a160 100644 --- a/apps/files/appinfo/routes.php +++ b/apps/files/appinfo/routes.php @@ -51,6 +51,11 @@ $application->registerRoutes( 'requirements' => array('tagName' => '.+'), ), array( + 'name' => 'API#getRecentFiles', + 'url' => '/api/v1/recent/', + 'verb' => 'GET' + ), + array( 'name' => 'API#updateFileSorting', 'url' => '/api/v1/sorting', 'verb' => 'POST' diff --git a/apps/files/lib/AppInfo/Application.php b/apps/files/lib/AppInfo/Application.php index fac8e3a3a4b..fc91e05ba7e 100644 --- a/apps/files/lib/AppInfo/Application.php +++ b/apps/files/lib/AppInfo/Application.php @@ -47,7 +47,8 @@ class Application extends App { $c->query('TagService'), $server->getPreviewManager(), $server->getShareManager(), - $server->getConfig() + $server->getConfig(), + $server->getUserFolder() ); }); diff --git a/apps/files/lib/Controller/ApiController.php b/apps/files/lib/Controller/ApiController.php index 57eb43bbe9c..8adc73a0a45 100644 --- a/apps/files/lib/Controller/ApiController.php +++ b/apps/files/lib/Controller/ApiController.php @@ -31,6 +31,7 @@ namespace OCA\Files\Controller; use OCP\AppFramework\Http; use OCP\AppFramework\Controller; +use OCP\Files\Folder; use OCP\IConfig; use OCP\IRequest; use OCP\AppFramework\Http\DataResponse; @@ -39,7 +40,7 @@ use OCP\AppFramework\Http\Response; use OCA\Files\Service\TagService; use OCP\IPreview; use OCP\Share\IManager; -use OCP\Files\Node; +use OC\Files\Node\Node; use OCP\IUserSession; /** @@ -58,12 +59,18 @@ class ApiController extends Controller { private $userSession; /** IConfig */ private $config; + /** @var Folder */ + private $userFolder; /** * @param string $appName * @param IRequest $request + * @param IUserSession $userSession * @param TagService $tagService * @param IPreview $previewManager + * @param IManager $shareManager + * @param IConfig $config + * @param Folder $userFolder */ public function __construct($appName, IRequest $request, @@ -71,13 +78,15 @@ class ApiController extends Controller { TagService $tagService, IPreview $previewManager, IManager $shareManager, - IConfig $config) { + IConfig $config, + Folder $userFolder) { parent::__construct($appName, $request); $this->userSession = $userSession; $this->tagService = $tagService; $this->previewManager = $previewManager; $this->shareManager = $shareManager; $this->config = $config; + $this->userFolder = $userFolder; } /** @@ -143,6 +152,28 @@ class ApiController extends Controller { } /** + * @param \OCP\Files\Node[] $nodes + * @return array + */ + private function formatNodes(array $nodes) { + return array_values(array_map(function (Node $node) { + /** @var \OC\Files\Node\Node $shareTypes */ + $shareTypes = $this->getShareTypes($node); + $file = \OCA\Files\Helper::formatFileInfo($node->getFileInfo()); + $parts = explode('/', dirname($node->getPath()), 4); + if (isset($parts[3])) { + $file['path'] = '/' . $parts[3]; + } else { + $file['path'] = '/'; + } + if (!empty($shareTypes)) { + $file['shareTypes'] = $shareTypes; + } + return $file; + }, $nodes)); + } + + /** * Returns a list of all files tagged with the given tag. * * @NoAdminRequired @@ -151,28 +182,29 @@ class ApiController extends Controller { * @return DataResponse */ public function getFilesByTag($tagName) { - $files = array(); $nodes = $this->tagService->getFilesByTag($tagName); - foreach ($nodes as &$node) { - $shareTypes = $this->getShareTypes($node); - $fileInfo = $node->getFileInfo(); - $file = \OCA\Files\Helper::formatFileInfo($fileInfo); - $parts = explode('/', dirname($fileInfo->getPath()), 4); - if(isset($parts[3])) { - $file['path'] = '/' . $parts[3]; - } else { - $file['path'] = '/'; - } + $files = $this->formatNodes($nodes); + foreach ($files as &$file) { $file['tags'] = [$tagName]; - if (!empty($shareTypes)) { - $file['shareTypes'] = $shareTypes; - } - $files[] = $file; } return new DataResponse(['files' => $files]); } /** + * Returns a list of recently modifed files. + * + * @NoAdminRequired + * + * @return DataResponse + */ + public function getRecentFiles() { + $since = time() - (60 * 60 * 24 * 7);//1 week + $nodes = $this->userFolder->getRecent($since); + $files = $this->formatNodes($nodes); + return new DataResponse(['files' => $files]); + } + + /** * Return a list of share types for outgoing shares * * @param Node $node file node |