From 294b3b8a0cf96400c08d622debbd57f7af3df0e2 Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Wed, 26 Oct 2022 15:12:46 -0700 Subject: [PATCH] albums: initial commit --- appinfo/routes.php | 7 ++++++ lib/Controller/ApiController.php | 32 ++++++++++++++++++++++++++ lib/Controller/PageController.php | 10 ++++++++ lib/Db/TimelineQuery.php | 1 + lib/Db/TimelineQueryAlbums.php | 38 +++++++++++++++++++++++++++++++ src/App.vue | 18 +++++++++++++-- src/components/Timeline.vue | 3 +++ src/router.ts | 9 ++++++++ src/services/DavRequests.ts | 9 +++++++- 9 files changed, 124 insertions(+), 3 deletions(-) create mode 100644 lib/Db/TimelineQueryAlbums.php diff --git a/appinfo/routes.php b/appinfo/routes.php index 5e363bcd..3889da4a 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -9,6 +9,7 @@ return [ ], ['name' => 'page#favorites', 'url' => '/favorites', 'verb' => 'GET'], ['name' => 'page#videos', 'url' => '/videos', 'verb' => 'GET'], + ['name' => 'page#albums', 'url' => '/albums', 'verb' => 'GET'], ['name' => 'page#archive', 'url' => '/archive', 'verb' => 'GET'], ['name' => 'page#thisday', 'url' => '/thisday', 'verb' => 'GET'], ['name' => 'page#people', 'url' => '/people/{name}', 'verb' => 'GET', @@ -24,11 +25,17 @@ return [ ['name' => 'api#days', 'url' => '/api/days', 'verb' => 'GET'], ['name' => 'api#dayPost', 'url' => '/api/days', 'verb' => 'POST'], ['name' => 'api#day', 'url' => '/api/days/{id}', 'verb' => 'GET'], + ['name' => 'api#tags', 'url' => '/api/tags', 'verb' => 'GET'], + + ['name' => 'api#albums', 'url' => '/api/albums', 'verb' => 'GET'], + ['name' => 'api#faces', 'url' => '/api/faces', 'verb' => 'GET'], ['name' => 'api#facePreview', 'url' => '/api/faces/preview/{id}', 'verb' => 'GET'], + ['name' => 'api#imageInfo', 'url' => '/api/info/{id}', 'verb' => 'GET'], ['name' => 'api#imageEdit', 'url' => '/api/edit/{id}', 'verb' => 'PATCH'], + ['name' => 'api#archive', 'url' => '/api/archive/{id}', 'verb' => 'PATCH'], // Config API diff --git a/lib/Controller/ApiController.php b/lib/Controller/ApiController.php index 8dc8ac68..c8ef2437 100644 --- a/lib/Controller/ApiController.php +++ b/lib/Controller/ApiController.php @@ -253,6 +253,30 @@ class ApiController extends Controller return new JSONResponse($list, Http::STATUS_OK); } + /** + * @NoAdminRequired + * @NoCSRFRequired + * + * Get list of albums with counts of images + */ + public function albums(): JSONResponse + { + $user = $this->userSession->getUser(); + if (null === $user) { + return new JSONResponse([], Http::STATUS_PRECONDITION_FAILED); + } + + // Check tags enabled for this user + if (!$this->albumsIsEnabled()) { + return new JSONResponse(['message' => 'Albums not enabled for user'], Http::STATUS_PRECONDITION_FAILED); + } + + // Run actual query + $list = $this->timelineQuery->getAlbums($user->getUID()); + + return new JSONResponse($list, Http::STATUS_OK); + } + /** * @NoAdminRequired * @@ -737,6 +761,14 @@ class ApiController extends Controller return $folder; } + /** + * Check if albums are enabled for this user. + */ + private function albumsIsEnabled(): bool + { + return $this->appManager->isEnabledForUser('photos'); + } + /** * Check if tags is enabled for this user. */ diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index 5df17e23..2c145e08 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -120,6 +120,16 @@ class PageController extends Controller return $this->main(); } + /** + * @NoAdminRequired + * + * @NoCSRFRequired + */ + public function albums() + { + return $this->main(); + } + /** * @NoAdminRequired * diff --git a/lib/Db/TimelineQuery.php b/lib/Db/TimelineQuery.php index f4d798c0..8e8081dd 100644 --- a/lib/Db/TimelineQuery.php +++ b/lib/Db/TimelineQuery.php @@ -12,6 +12,7 @@ class TimelineQuery use TimelineQueryFaces; use TimelineQueryFilters; use TimelineQueryTags; + use TimelineQueryAlbums; protected IDBConnection $connection; diff --git a/lib/Db/TimelineQueryAlbums.php b/lib/Db/TimelineQueryAlbums.php new file mode 100644 index 00000000..aeaf1c90 --- /dev/null +++ b/lib/Db/TimelineQueryAlbums.php @@ -0,0 +1,38 @@ +connection->getQueryBuilder(); + + // SELECT everything from albums + $query->select('*')->from('photos_albums', 'pa')->where( + $query->expr()->eq('user', $query->createNamedParameter($uid)), + ); + + // GROUP and ORDER by + $query->orderBy('pa.created', 'DESC'); + $query->addOrderBy('pa.album_id', 'DESC'); // tie-breaker + + // FETCH all albums + $albums = $query->executeQuery()->fetchAll(); + + // Post process + foreach ($albums as &$row) { + $row['album_id'] = (int) $row['id']; + $row['created'] = (int) $row['count']; + $row['last_added_photo'] = (int) $row['last_added_photo']; + } + + return $albums; + } +} diff --git a/src/App.vue b/src/App.vue index a316e631..f5650473 100644 --- a/src/App.vue +++ b/src/App.vue @@ -23,6 +23,10 @@ :title="t('memories', 'Videos')">