Allow wildcard day query
parent
66f479844e
commit
68a40ffbc7
|
@ -208,10 +208,21 @@ class ApiController extends Controller {
|
|||
}
|
||||
$uid = $user->getUID();
|
||||
|
||||
// Split at commas and convert all parts to int
|
||||
$day_ids = array_map(function ($part) {
|
||||
return intval($part);
|
||||
}, explode(",", $id));
|
||||
// Check for wildcard
|
||||
$day_ids = [];
|
||||
if ($id === "*") {
|
||||
$day_ids = null;
|
||||
} else {
|
||||
// Split at commas and convert all parts to int
|
||||
$day_ids = array_map(function ($part) {
|
||||
return intval($part);
|
||||
}, explode(",", $id));
|
||||
}
|
||||
|
||||
// Check if $day_ids is empty
|
||||
if (!is_null($day_ids) && count($day_ids) === 0) {
|
||||
return new JSONResponse([], Http::STATUS_OK);
|
||||
}
|
||||
|
||||
// Get the folder to show
|
||||
$folder = $this->getRequestFolder();
|
||||
|
|
|
@ -147,7 +147,7 @@ trait TimelineQueryDays {
|
|||
public function getDay(
|
||||
Folder &$folder,
|
||||
string $uid,
|
||||
array $day_ids,
|
||||
$day_ids,
|
||||
bool $recursive,
|
||||
bool $archive,
|
||||
array $queryTransforms = []
|
||||
|
@ -162,8 +162,15 @@ trait TimelineQueryDays {
|
|||
// when using DISTINCT on selected fields
|
||||
$query->select($fileid, 'f.etag', 'm.isvideo', 'vco.categoryid', 'm.datetaken', 'm.dayid')
|
||||
->from('memories', 'm')
|
||||
->innerJoin('m', 'filecache', 'f', $this->getFilecacheJoinQuery($query, $folder, $recursive, $archive))
|
||||
->andWhere($query->expr()->in('m.dayid', $query->createNamedParameter($day_ids, IQueryBuilder::PARAM_INT_ARRAY)));
|
||||
->innerJoin('m', 'filecache', 'f', $this->getFilecacheJoinQuery($query, $folder, $recursive, $archive));
|
||||
|
||||
// Filter by dayid unless wildcard
|
||||
if (!is_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);
|
||||
}
|
||||
|
||||
// Add favorite field
|
||||
$this->addFavoriteTag($query, $uid);
|
||||
|
|
|
@ -46,6 +46,10 @@ trait TimelineQueryFilters {
|
|||
}
|
||||
|
||||
public function transformLimitDay(IQueryBuilder &$query, string $userId, int $limit) {
|
||||
// The valid range for limit is 1 - 100; otherwise abort
|
||||
if ($limit < 1 || $limit > 100) {
|
||||
return;
|
||||
}
|
||||
$query->setMaxResults($limit);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue