Add the ability to filtered on watched status and the ability to customize the history item entity view.

This commit is contained in:
arabcoders
2025-05-05 17:07:21 +03:00
parent bcbe71a158
commit 29dbf2f06f

View File

@@ -71,11 +71,12 @@ final class Index
$data = DataUtil::fromArray($request->getQueryParams());
$es = fn(string $val) => $db->escapeIdentifier($val, true);
$es = fn (string $val) => $db->escapeIdentifier($val, true);
$filters = [];
$page = (int)$data->get('page', 1);
$perpage = (int)$data->get('perpage', 12);
$customView = $data->get('view', null);
$start = (($page <= 2) ? ((1 === $page) ? 0 : $perpage) : $perpage * ($page - 1));
$start = (!$page) ? 0 : $start;
@@ -111,6 +112,12 @@ final class Index
$filters['rguid'] = $data->get('rguid');
}
if ($data->has(iState::COLUMN_WATCHED)) {
$where[] = $es(iState::COLUMN_WATCHED) . ' = :' . iState::COLUMN_WATCHED;
$params[iState::COLUMN_WATCHED] = (int)$data->get(iState::COLUMN_WATCHED);
$filters[iState::COLUMN_WATCHED] = $data->get(iState::COLUMN_WATCHED);
}
if ($data->get(iState::COLUMN_ID)) {
$where[] = $es(iState::COLUMN_ID) . ' = :' . iState::COLUMN_ID;
$params[iState::COLUMN_ID] = $data->get(iState::COLUMN_ID);
@@ -340,9 +347,9 @@ final class Index
}
if (null === ($matches['field'] ?? null) || false === in_array(
$matches['field'],
self::COLUMNS_SORTABLE
)) {
$matches['field'],
self::COLUMNS_SORTABLE
)) {
continue;
}
@@ -416,6 +423,11 @@ final class Index
'description' => 'Search using local history id.',
'type' => 'int',
],
[
'key' => 'watched',
'description' => 'Search using watched status.',
'type' => [ '0', '1'],
],
[
'key' => 'via',
'display' => 'Backend',
@@ -497,8 +509,19 @@ final class Index
],
];
while ($row = $stmt->fetch()) {
$response['history'][] = $this->formatEntity($row, userContext: $userContext);
$entity = $this->formatEntity($row, userContext: $userContext);
if (null !== $customView) {
$customEntity = [];
foreach (explode(',', $customView) as $k) {
$customEntity = ag_set($customEntity, $k, ag($entity, $k, null));
}
$entity = $customEntity;
}
$response['history'][] = $entity;
}
return api_response(Status::OK, $response);
@@ -556,7 +579,7 @@ final class Index
'ffprobe' => $data,
'subtitles' => array_filter(
findSideCarFiles(new SplFileInfo($file)),
fn($sideCar) => isset(Subtitle::FORMATS[getExtension($sideCar)])
fn ($sideCar) => isset(Subtitle::FORMATS[getExtension($sideCar)])
)
];
}