add recent files api endpoint
This commit is contained in:
parent
e321ecd592
commit
b94ff97a77
3 changed files with 56 additions and 18 deletions
|
@ -50,6 +50,11 @@ $application->registerRoutes(
|
|||
'verb' => 'GET',
|
||||
'requirements' => array('tagName' => '.+'),
|
||||
),
|
||||
array(
|
||||
'name' => 'API#getRecentFiles',
|
||||
'url' => '/api/v1/recent/',
|
||||
'verb' => 'GET'
|
||||
),
|
||||
array(
|
||||
'name' => 'API#updateFileSorting',
|
||||
'url' => '/api/v1/sorting',
|
||||
|
|
|
@ -47,7 +47,8 @@ class Application extends App {
|
|||
$c->query('TagService'),
|
||||
$server->getPreviewManager(),
|
||||
$server->getShareManager(),
|
||||
$server->getConfig()
|
||||
$server->getConfig(),
|
||||
$server->getUserFolder()
|
||||
);
|
||||
});
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -142,6 +151,28 @@ class ApiController extends Controller {
|
|||
return new DataResponse($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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.
|
||||
*
|
||||
|
@ -151,27 +182,28 @@ 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
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue