days: remove wildcard API

Signed-off-by: Varun Patil <radialapps@gmail.com>
pull/877/head
Varun Patil 2023-10-14 16:03:59 -07:00
parent b29ff26a18
commit eace12df0f
4 changed files with 22 additions and 40 deletions

View File

@ -4,7 +4,7 @@ function getWildcard($param)
{ {
return [ return [
'requirements' => [$param => '.*'], 'requirements' => [$param => '.*'],
'defaults' => [$param => ''] 'defaults' => [$param => ''],
]; ];
} }
@ -98,5 +98,5 @@ return [
// Service worker // Service worker
['name' => 'Other#serviceWorker', 'url' => '/service-worker.js', 'verb' => 'GET'], ['name' => 'Other#serviceWorker', 'url' => '/service-worker.js', 'verb' => 'GET'],
] ],
]; ];

View File

@ -24,7 +24,6 @@ declare(strict_types=1);
namespace OCA\Memories\Controller; namespace OCA\Memories\Controller;
use OCA\Memories\ClustersBackend; use OCA\Memories\ClustersBackend;
use OCA\Memories\Exceptions;
use OCA\Memories\Util; use OCA\Memories\Util;
use OCP\AppFramework\Http; use OCP\AppFramework\Http;
use OCP\AppFramework\Http\JSONResponse; use OCP\AppFramework\Http\JSONResponse;
@ -70,23 +69,18 @@ class DaysController extends GenericApiController
public function day(string $id): Http\Response public function day(string $id): Http\Response
{ {
return Util::guardEx(function () use ($id) { return Util::guardEx(function () use ($id) {
// Check for wildcard // Split at commas and convert all parts to int
$dayIds = []; /** @var int[] */
if ('*' === $id) { $dayIds = array_map(static fn ($p) => (int) $p, explode(',', $id));
$dayIds = null;
} else {
// Split at commas and convert all parts to int
$dayIds = array_map(static fn ($p) => (int) $p, explode(',', $id));
}
// Check if $dayIds is empty // Check if $dayIds is empty
if (null !== $dayIds && 0 === \count($dayIds)) { if (empty($dayIds)) {
return new JSONResponse([], Http::STATUS_OK); return new JSONResponse([], Http::STATUS_OK);
} }
// Convert to actual dayIds if month view // Convert to actual dayIds if month view
if ($this->isMonthView()) { if ($this->isMonthView()) {
$dayIds = $this->monthIdToDayIds((int) $dayIds[0]); $dayIds = $this->monthIdToDayIds($dayIds[0]);
} }
// Run actual query // Run actual query
@ -99,9 +93,9 @@ class DaysController extends GenericApiController
); );
// Force month id for dayId for month view // Force month id for dayId for month view
if ($this->isMonthView() && $dayIds) { if ($this->isMonthView()) {
foreach ($list as &$photo) { foreach ($list as &$photo) {
$photo['dayid'] = (int) $dayIds[0]; $photo['dayid'] = $dayIds[0];
} }
} }
@ -118,17 +112,12 @@ class DaysController extends GenericApiController
* @NoAdminRequired * @NoAdminRequired
* *
* @PublicPage * @PublicPage
*
* @param int[] $dayIds
*/ */
public function dayPost(): Http\Response public function dayPost(array $dayIds): Http\Response
{ {
return Util::guardEx(function () { return $this->day(implode(',', $dayIds));
$id = $this->request->getParam('body_ids');
if (null === $id) {
throw Exceptions::MissingParameter('body_ids');
}
return $this->day($id);
});
} }
/** /**

View File

@ -57,16 +57,16 @@ trait TimelineQueryDays
/** /**
* Get the day response from the database for the timeline. * Get the day response from the database for the timeline.
* *
* @param ?int[] $day_ids The day ids to fetch * @param int[] $day_ids The day ids to fetch
* @param bool $recursive If the query should be recursive * @param bool $recursive If the query should be recursive
* @param bool $archive If the query should include only the archive folder * @param bool $archive If the query should include only the archive folder
* @param bool $hidden If the query should include hidden files * @param bool $hidden If the query should include hidden files
* @param array $queryTransforms The query transformations to apply * @param array $queryTransforms The query transformations to apply
* *
* @return array An array of day responses * @return array An array of day responses
*/ */
public function getDay( public function getDay(
?array $day_ids, array $day_ids,
bool $recursive, bool $recursive,
bool $archive, bool $archive,
bool $hidden, bool $hidden,
@ -92,13 +92,8 @@ trait TimelineQueryDays
// JOIN with mimetypes to get the mimetype // JOIN with mimetypes to get the mimetype
$query->join('f', 'mimetypes', 'mimetypes', $query->expr()->eq('f.mimetype', 'mimetypes.id')); $query->join('f', 'mimetypes', 'mimetypes', $query->expr()->eq('f.mimetype', 'mimetypes.id'));
// Filter by dayid unless wildcard // Filter by dayid
if (null !== $day_ids) { $query->andWhere($query->expr()->in('m.dayid', $query->createNamedParameter($day_ids, IQueryBuilder::PARAM_INT_ARRAY)));
$query->andWhere($query->expr()->in('m.dayid', $query->createNamedParameter($day_ids, IQueryBuilder::PARAM_INT_ARRAY)));
} else {
// Limit wildcard to 100 results
$query->setMaxResults(100);
}
// Add favorite field // Add favorite field
$this->addFavoriteTag($query); $this->addFavoriteTag($query);

View File

@ -23,9 +23,7 @@ export async function getOnThisDayRaw() {
} }
} }
const res = await axios.post<IPhoto[]>(API.DAYS(), { const res = await axios.post<IPhoto[]>(API.DAYS(), { dayIds });
body_ids: dayIds.join(','),
});
res.data.forEach(utils.convertFlags); res.data.forEach(utils.convertFlags);
return res.data; return res.data;