From eace12df0f0df232320a87bd48b7d797efbeade2 Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Sat, 14 Oct 2023 16:03:59 -0700 Subject: [PATCH] days: remove wildcard API Signed-off-by: Varun Patil --- appinfo/routes.php | 4 ++-- lib/Controller/DaysController.php | 33 +++++++++++-------------------- lib/Db/TimelineQueryDays.php | 21 ++++++++------------ src/services/dav/onthisday.ts | 4 +--- 4 files changed, 22 insertions(+), 40 deletions(-) diff --git a/appinfo/routes.php b/appinfo/routes.php index af060c8e..ff58882d 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -4,7 +4,7 @@ function getWildcard($param) { return [ 'requirements' => [$param => '.*'], - 'defaults' => [$param => ''] + 'defaults' => [$param => ''], ]; } @@ -98,5 +98,5 @@ return [ // Service worker ['name' => 'Other#serviceWorker', 'url' => '/service-worker.js', 'verb' => 'GET'], - ] + ], ]; diff --git a/lib/Controller/DaysController.php b/lib/Controller/DaysController.php index a51284d4..560e0cd0 100644 --- a/lib/Controller/DaysController.php +++ b/lib/Controller/DaysController.php @@ -24,7 +24,6 @@ declare(strict_types=1); namespace OCA\Memories\Controller; use OCA\Memories\ClustersBackend; -use OCA\Memories\Exceptions; use OCA\Memories\Util; use OCP\AppFramework\Http; use OCP\AppFramework\Http\JSONResponse; @@ -70,23 +69,18 @@ class DaysController extends GenericApiController public function day(string $id): Http\Response { return Util::guardEx(function () use ($id) { - // Check for wildcard - $dayIds = []; - if ('*' === $id) { - $dayIds = null; - } else { - // Split at commas and convert all parts to int - $dayIds = array_map(static fn ($p) => (int) $p, explode(',', $id)); - } + // Split at commas and convert all parts to int + /** @var int[] */ + $dayIds = array_map(static fn ($p) => (int) $p, explode(',', $id)); // Check if $dayIds is empty - if (null !== $dayIds && 0 === \count($dayIds)) { + if (empty($dayIds)) { return new JSONResponse([], Http::STATUS_OK); } // Convert to actual dayIds if month view if ($this->isMonthView()) { - $dayIds = $this->monthIdToDayIds((int) $dayIds[0]); + $dayIds = $this->monthIdToDayIds($dayIds[0]); } // Run actual query @@ -99,9 +93,9 @@ class DaysController extends GenericApiController ); // Force month id for dayId for month view - if ($this->isMonthView() && $dayIds) { + if ($this->isMonthView()) { foreach ($list as &$photo) { - $photo['dayid'] = (int) $dayIds[0]; + $photo['dayid'] = $dayIds[0]; } } @@ -118,17 +112,12 @@ class DaysController extends GenericApiController * @NoAdminRequired * * @PublicPage + * + * @param int[] $dayIds */ - public function dayPost(): Http\Response + public function dayPost(array $dayIds): Http\Response { - return Util::guardEx(function () { - $id = $this->request->getParam('body_ids'); - if (null === $id) { - throw Exceptions::MissingParameter('body_ids'); - } - - return $this->day($id); - }); + return $this->day(implode(',', $dayIds)); } /** diff --git a/lib/Db/TimelineQueryDays.php b/lib/Db/TimelineQueryDays.php index c7981c5f..1d8a9be3 100644 --- a/lib/Db/TimelineQueryDays.php +++ b/lib/Db/TimelineQueryDays.php @@ -57,16 +57,16 @@ trait TimelineQueryDays /** * Get the day response from the database for the timeline. * - * @param ?int[] $day_ids The day ids to fetch - * @param bool $recursive If the query should be recursive - * @param bool $archive If the query should include only the archive folder - * @param bool $hidden If the query should include hidden files - * @param array $queryTransforms The query transformations to apply + * @param int[] $day_ids The day ids to fetch + * @param bool $recursive If the query should be recursive + * @param bool $archive If the query should include only the archive folder + * @param bool $hidden If the query should include hidden files + * @param array $queryTransforms The query transformations to apply * * @return array An array of day responses */ public function getDay( - ?array $day_ids, + array $day_ids, bool $recursive, bool $archive, bool $hidden, @@ -92,13 +92,8 @@ trait TimelineQueryDays // JOIN with mimetypes to get the mimetype $query->join('f', 'mimetypes', 'mimetypes', $query->expr()->eq('f.mimetype', 'mimetypes.id')); - // Filter by dayid unless wildcard - if (null !== $day_ids) { - $query->andWhere($query->expr()->in('m.dayid', $query->createNamedParameter($day_ids, IQueryBuilder::PARAM_INT_ARRAY))); - } else { - // Limit wildcard to 100 results - $query->setMaxResults(100); - } + // Filter by dayid + $query->andWhere($query->expr()->in('m.dayid', $query->createNamedParameter($day_ids, IQueryBuilder::PARAM_INT_ARRAY))); // Add favorite field $this->addFavoriteTag($query); diff --git a/src/services/dav/onthisday.ts b/src/services/dav/onthisday.ts index 1d95d2a4..15d6b9bd 100644 --- a/src/services/dav/onthisday.ts +++ b/src/services/dav/onthisday.ts @@ -23,9 +23,7 @@ export async function getOnThisDayRaw() { } } - const res = await axios.post(API.DAYS(), { - body_ids: dayIds.join(','), - }); + const res = await axios.post(API.DAYS(), { dayIds }); res.data.forEach(utils.convertFlags); return res.data;