Skip to content

Commit

Permalink
endpoints to fetch item's children
Browse files Browse the repository at this point in the history
For /users/i:objectUserID/items/:objectKey/children and /groups/i:objectGroupID/items/:objectKey/children.
Only allows get requests.
Fixes: #113
  • Loading branch information
abaevbog committed Jun 14, 2023
1 parent 2cf66c3 commit bd7dd63
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions controllers/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class ApiController extends Controller {
protected $objectKey;
protected $objectName;
protected $subset;
protected $getOnly;
protected $singleObject;
protected $publications = false;
protected $legacyPublications = false;
Expand Down Expand Up @@ -446,6 +447,7 @@ public function init($extra) {

$this->scopeObject = !empty($extra['scopeObject']) ? $extra['scopeObject'] : $this->scopeObject;
$this->subset = !empty($extra['subset']) ? $extra['subset'] : $this->subset;
$this->getOnly = !empty($extra['getOnly']) ? $extra['getOnly'] : $this->getOnly;

$this->fileMode = !empty($extra['file'])
? (!empty($_GET['info']) ? 'info' : 'download')
Expand Down
3 changes: 3 additions & 0 deletions controllers/ItemsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,9 @@ public function items() {
);
}
else if ($this->subset == 'children') {
if ($this->getOnly) {
$this->allowMethods(array('GET'));
}
$item = Zotero_Items::getByLibraryAndKey($this->objectLibraryID, $this->objectKey);
if (!$item) {
$this->e404("Item not found");
Expand Down
2 changes: 2 additions & 0 deletions include/config/routes.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
$router->map('/groups/i:objectGroupID/items/:objectKey/file', array('controller' => 'Items', 'extra' => array('allowHTTP' => true, 'file' => true)));
$router->map('/groups/i:objectGroupID/items/:objectKey/file/view', array('controller' => 'Items', 'extra' => array('allowHTTP' => true, 'file' => true, 'view' => true)));
$router->map('/groups/i:objectGroupID/items/:objectKey/file/view/url', ['controller' => 'Items', 'extra' => ['file' => true, 'viewurl' => true]]);
$router->map('/users/i:objectUserID/items/:objectKey/children', ['controller' => 'Items', 'extra' => ['subset' => 'children', 'getOnly' => true]]);
$router->map('/groups/i:objectGroupID/items/:objectKey/children', ['controller' => 'Items', 'extra' => ['subset' => 'children', 'getOnly' => true]]);

// Full-text content
$router->map('/users/i:objectUserID/items/:objectKey/fulltext', array('controller' => 'FullText', 'action' => 'itemContent'));
Expand Down

0 comments on commit bd7dd63

Please sign in to comment.