Check enabled recognize and version
parent
520f106f22
commit
1505218fd0
|
@ -29,6 +29,7 @@ use OCA\Memories\AppInfo\Application;
|
||||||
use OCA\Memories\Db\TimelineQuery;
|
use OCA\Memories\Db\TimelineQuery;
|
||||||
use OCA\Memories\Db\TimelineWrite;
|
use OCA\Memories\Db\TimelineWrite;
|
||||||
use OCA\Memories\Exif;
|
use OCA\Memories\Exif;
|
||||||
|
use OCP\App\IAppManager;
|
||||||
use OCP\AppFramework\Controller;
|
use OCP\AppFramework\Controller;
|
||||||
use OCP\AppFramework\Http;
|
use OCP\AppFramework\Http;
|
||||||
use OCP\AppFramework\Http\JSONResponse;
|
use OCP\AppFramework\Http\JSONResponse;
|
||||||
|
@ -45,6 +46,7 @@ class ApiController extends Controller {
|
||||||
private IUserSession $userSession;
|
private IUserSession $userSession;
|
||||||
private IDBConnection $connection;
|
private IDBConnection $connection;
|
||||||
private IRootFolder $rootFolder;
|
private IRootFolder $rootFolder;
|
||||||
|
private IAppManager $appManager;
|
||||||
private TimelineQuery $timelineQuery;
|
private TimelineQuery $timelineQuery;
|
||||||
private TimelineWrite $timelineWrite;
|
private TimelineWrite $timelineWrite;
|
||||||
|
|
||||||
|
@ -53,7 +55,8 @@ class ApiController extends Controller {
|
||||||
IConfig $config,
|
IConfig $config,
|
||||||
IUserSession $userSession,
|
IUserSession $userSession,
|
||||||
IDBConnection $connection,
|
IDBConnection $connection,
|
||||||
IRootFolder $rootFolder) {
|
IRootFolder $rootFolder,
|
||||||
|
IAppManager $appManager) {
|
||||||
|
|
||||||
parent::__construct(Application::APPNAME, $request);
|
parent::__construct(Application::APPNAME, $request);
|
||||||
|
|
||||||
|
@ -61,6 +64,7 @@ class ApiController extends Controller {
|
||||||
$this->userSession = $userSession;
|
$this->userSession = $userSession;
|
||||||
$this->connection = $connection;
|
$this->connection = $connection;
|
||||||
$this->rootFolder = $rootFolder;
|
$this->rootFolder = $rootFolder;
|
||||||
|
$this->appManager = $appManager;
|
||||||
$this->timelineQuery = new TimelineQuery($this->connection);
|
$this->timelineQuery = new TimelineQuery($this->connection);
|
||||||
$this->timelineWrite = new TimelineWrite($connection);
|
$this->timelineWrite = new TimelineWrite($connection);
|
||||||
}
|
}
|
||||||
|
@ -82,15 +86,19 @@ class ApiController extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filter only for one face
|
// Filter only for one face
|
||||||
$faceId = $this->request->getParam('face');
|
if ($this->recognizeIsEnabled()) {
|
||||||
if ($faceId) {
|
$faceId = $this->request->getParam('face');
|
||||||
$transforms[] = array($this->timelineQuery, 'transformFaceFilter', intval($faceId));
|
if ($faceId) {
|
||||||
|
$transforms[] = array($this->timelineQuery, 'transformFaceFilter', intval($faceId));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filter only for one tag
|
// Filter only for one tag
|
||||||
$tagName = $this->request->getParam('tag');
|
if ($this->tagsIsEnabled()) {
|
||||||
if ($tagName) {
|
$tagName = $this->request->getParam('tag');
|
||||||
$transforms[] = array($this->timelineQuery, 'transformTagFilter', $tagName);
|
if ($tagName) {
|
||||||
|
$transforms[] = array($this->timelineQuery, 'transformTagFilter', $tagName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Limit number of responses for day query
|
// Limit number of responses for day query
|
||||||
|
@ -296,6 +304,11 @@ class ApiController extends Controller {
|
||||||
return new JSONResponse([], Http::STATUS_PRECONDITION_FAILED);
|
return new JSONResponse([], Http::STATUS_PRECONDITION_FAILED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check tags enabled for this user
|
||||||
|
if (!$this->tagsIsEnabled()) {
|
||||||
|
return new JSONResponse(["message" => "Tags not enabled for user"], Http::STATUS_PRECONDITION_FAILED);
|
||||||
|
}
|
||||||
|
|
||||||
// If this isn't the timeline folder then things aren't going to work
|
// If this isn't the timeline folder then things aren't going to work
|
||||||
$folder = $this->getRequestFolder();
|
$folder = $this->getRequestFolder();
|
||||||
if (is_null($folder)) {
|
if (is_null($folder)) {
|
||||||
|
@ -321,6 +334,11 @@ class ApiController extends Controller {
|
||||||
return new JSONResponse([], Http::STATUS_PRECONDITION_FAILED);
|
return new JSONResponse([], Http::STATUS_PRECONDITION_FAILED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check faces enabled for this user
|
||||||
|
if (!$this->recognizeIsEnabled()) {
|
||||||
|
return new JSONResponse(["message" => "Recognize app not enabled or not v3+"], Http::STATUS_PRECONDITION_FAILED);
|
||||||
|
}
|
||||||
|
|
||||||
// If this isn't the timeline folder then things aren't going to work
|
// If this isn't the timeline folder then things aren't going to work
|
||||||
$folder = $this->getRequestFolder();
|
$folder = $this->getRequestFolder();
|
||||||
if (is_null($folder)) {
|
if (is_null($folder)) {
|
||||||
|
@ -347,6 +365,11 @@ class ApiController extends Controller {
|
||||||
return new JSONResponse([], Http::STATUS_PRECONDITION_FAILED);
|
return new JSONResponse([], Http::STATUS_PRECONDITION_FAILED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check faces enabled for this user
|
||||||
|
if (!$this->recognizeIsEnabled()) {
|
||||||
|
return new JSONResponse(["message" => "Recognize app not enabled"], Http::STATUS_PRECONDITION_FAILED);
|
||||||
|
}
|
||||||
|
|
||||||
// If this isn't the timeline folder then things aren't going to work
|
// If this isn't the timeline folder then things aren't going to work
|
||||||
$folder = $this->getRequestFolder();
|
$folder = $this->getRequestFolder();
|
||||||
if (is_null($folder)) {
|
if (is_null($folder)) {
|
||||||
|
@ -548,6 +571,25 @@ class ApiController extends Controller {
|
||||||
return new JSONResponse([], Http::STATUS_OK);
|
return new JSONResponse([], Http::STATUS_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if tags is enabled for this user
|
||||||
|
*/
|
||||||
|
private function tagsIsEnabled(): bool {
|
||||||
|
return $this->appManager->isEnabledForUser('systemtags');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if recognize is enabled for this user
|
||||||
|
*/
|
||||||
|
private function recognizeIsEnabled(): bool {
|
||||||
|
if (!$this->appManager->isEnabledForUser('recognize')) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$v = $this->appManager->getAppInfo('recognize')["version"];
|
||||||
|
return version_compare($v, "3.0.0-alpha", ">=");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @NoAdminRequired
|
* @NoAdminRequired
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue