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 [
'requirements' => [$param => '.*'],
'defaults' => [$param => '']
'defaults' => [$param => ''],
];
}
@ -98,5 +98,5 @@ return [
// Service worker
['name' => 'Other#serviceWorker', 'url' => '/service-worker.js', 'verb' => 'GET'],
]
],
];

View File

@ -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
/** @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));
}
/**

View File

@ -57,7 +57,7 @@ trait TimelineQueryDays
/**
* 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 $archive If the query should include only the archive folder
* @param bool $hidden If the query should include hidden files
@ -66,7 +66,7 @@ trait TimelineQueryDays
* @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) {
// Filter by dayid
$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
$this->addFavoriteTag($query);

View File

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