refactor: add getShareNode to ApiBase
parent
6db1752359
commit
719022848b
|
@ -104,12 +104,7 @@ class ApiBase extends Controller
|
|||
}
|
||||
|
||||
// Public shared folder
|
||||
if ($token = $this->getShareToken()) {
|
||||
$share = $this->shareManager->getShareByToken($token)->getNode(); // throws exception if not found
|
||||
if (!$share instanceof Folder || !$share->isReadable() || !$share->isShareable()) {
|
||||
throw new \Exception('Share not found or invalid');
|
||||
}
|
||||
|
||||
if ($share = $this->getShareNode()) { // can throw
|
||||
$root->addFolder($share);
|
||||
|
||||
return $root;
|
||||
|
@ -200,21 +195,14 @@ class ApiBase extends Controller
|
|||
*/
|
||||
protected function getShareFile(int $id): ?File
|
||||
{
|
||||
$token = $this->getShareToken();
|
||||
if (null === $token) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
$share = $this->shareManager->getShareByToken($token)->getNode(); // throws exception if not found
|
||||
if (!$share instanceof Folder || !$share->isReadable() || !$share->isShareable()) {
|
||||
return null;
|
||||
if ($share = $this->getShareNode()) {
|
||||
return $this->getOneFileFromFolder($share, $id);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->getOneFileFromFolder($share, $id);
|
||||
return null;
|
||||
}
|
||||
|
||||
protected function isRecursive()
|
||||
|
@ -242,6 +230,21 @@ class ApiBase extends Controller
|
|||
return $this->request->getParam('folder_share');
|
||||
}
|
||||
|
||||
protected function getShareNode()
|
||||
{
|
||||
$token = $this->getShareToken();
|
||||
if (null === $token) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$share = $this->shareManager->getShareByToken($token)->getNode(); // throws exception if not found
|
||||
if (!$share instanceof Folder || !$share->isReadable() || !$share->isShareable()) {
|
||||
throw new \Exception('Share not found or invalid');
|
||||
}
|
||||
|
||||
return $share;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if albums are enabled for this user.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue