api: add hidden day option

Signed-off-by: Varun Patil <radialapps@gmail.com>
pull/807/merge
Varun Patil 2023-10-02 17:22:05 -07:00
parent 5820c53857
commit 51b096c194
2 changed files with 36 additions and 7 deletions

View File

@ -94,6 +94,7 @@ class DaysController extends GenericApiController
$dayIds,
$this->isRecursive(),
$this->isArchive(),
$this->isHidden(),
$this->getTransformations(),
);
@ -211,6 +212,7 @@ class DaysController extends GenericApiController
$preloadDayIds,
$this->isRecursive(),
$this->isArchive(),
$this->isHidden(),
$transforms,
);
@ -276,6 +278,11 @@ class DaysController extends GenericApiController
return null !== $this->request->getParam('archive');
}
private function isHidden()
{
return null !== $this->request->getParam('hidden');
}
private function isMonthView()
{
return null !== $this->request->getParam('monthView');

View File

@ -60,6 +60,7 @@ trait TimelineQueryDays
* @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
@ -68,6 +69,7 @@ trait TimelineQueryDays
?array $day_ids,
bool $recursive,
bool $archive,
bool $hidden,
array $queryTransforms = []
): array {
$query = $this->connection->getQueryBuilder();
@ -82,6 +84,11 @@ trait TimelineQueryDays
->from('memories', 'm')
;
// Add hidden field
if ($hidden) {
$query->addSelect('cte_f.hidden');
}
// JOIN with mimetypes to get the mimetype
$query->join('f', 'mimetypes', 'mimetypes', $query->expr()->eq('f.mimetype', 'mimetypes.id'));
@ -104,7 +111,7 @@ trait TimelineQueryDays
$this->applyAllTransforms($queryTransforms, $query, false);
// JOIN with filecache for existing files
$query = $this->joinFilecache($query, null, $recursive, $archive);
$query = $this->joinFilecache($query, null, $recursive, $archive, $hidden);
// FETCH all photos in this day
$day = $this->executeQueryWithCTEs($query)->fetchAll();
@ -124,9 +131,9 @@ trait TimelineQueryDays
$types = $query->getParameterTypes();
// Get SQL
$CTE_SQL = \array_key_exists('cteFoldersArchive', $params) && $params['cteFoldersArchive']
$CTE_SQL = \array_key_exists('cteFoldersArchive', $params)
? self::CTE_FOLDERS_ARCHIVE()
: self::CTE_FOLDERS(false);
: self::CTE_FOLDERS(\array_key_exists('cteIncludeHidden', $params));
// Add WITH clause if needed
if (false !== strpos($sql, 'cte_folders')) {
@ -143,12 +150,14 @@ trait TimelineQueryDays
* @param TimelineRoot $root Either the top folder or null for all
* @param bool $recursive Whether to get the days recursively
* @param bool $archive Whether to get the days only from the archive folder
* @param bool $hidden Whether to include hidden files
*/
public function joinFilecache(
IQueryBuilder $query,
?TimelineRoot $root = null,
bool $recursive = true,
bool $archive = false
bool $archive = false,
bool $hidden = false
): IQueryBuilder {
// This will throw if the root is illegally empty
$root = $this->root($root);
@ -163,7 +172,7 @@ trait TimelineQueryDays
$pathOp = null;
if ($recursive) {
// Join with folders CTE
$this->addSubfolderJoinParams($query, $root, $archive);
$this->addSubfolderJoinParams($query, $root, $archive, $hidden);
$query->innerJoin('f', 'cte_folders', 'cte_f', $query->expr()->eq('f.parent', 'cte_f.fileid'));
} else {
// If getting non-recursively folder only check for parent
@ -230,6 +239,11 @@ trait TimelineQueryDays
// compute AUID and discard epoch and size
$row['auid'] = Exif::getAUID($epoch, $size);
}
// Get hidden field if present
if (\array_key_exists('hidden', $row)) {
$row['hidden'] = (bool) $row['hidden'];
}
}
/**
@ -238,10 +252,18 @@ trait TimelineQueryDays
private function addSubfolderJoinParams(
IQueryBuilder &$query,
TimelineRoot &$root,
bool $archive
bool $archive,
bool $hidden
) {
// Add query parameters
$query->setParameter('topFolderIds', $root->getIds(), IQueryBuilder::PARAM_INT_ARRAY);
$query->setParameter('cteFoldersArchive', $archive, IQueryBuilder::PARAM_BOOL);
if ($archive) {
$query->setParameter('cteFoldersArchive', true, IQueryBuilder::PARAM_BOOL);
}
if ($hidden) {
$query->setParameter('cteIncludeHidden', true, IQueryBuilder::PARAM_BOOL);
}
}
}