feat(web): dropdown sort and time filters with year support
This commit is contained in:
1 parent
bc3bef0743
commit
9be7d1cab2
10 files changed
+191
-67
No files matched your search
@@ -294,6 +294,7 @@ border-color:#3a2c22;color:#f3e9dc}button{background:#e9b97c;color:#2a1a10}}
|
||||
self._send_json(HTTPStatus.OK, queries.list_videos(
|
||||
sort=_param(query, "sort", "heat"),
|
||||
within_days=_optional_int(query, "within_days"),
|
||||
year=_year_param(query),
|
||||
growth_days=_int_param(query, "growth_days", 7, 1, 365),
|
||||
folder_id=_optional_int(query, "folder"),
|
||||
q=_optional_str(query, "q"),
|
||||
@@ -326,6 +327,7 @@ border-color:#3a2c22;color:#f3e9dc}button{background:#e9b97c;color:#2a1a10}}
|
||||
self._send_json(HTTPStatus.OK, queries.list_ups(
|
||||
sort=_param(query, "sort", "efficiency"),
|
||||
within_days=_optional_int(query, "within_days"),
|
||||
year=_year_param(query),
|
||||
q=_optional_str(query, "q"),
|
||||
min_videos=_int_param(query, "min_videos", 1, 1, 10000),
|
||||
page=_int_param(query, "page", 1, 1, 1_000_000),
|
||||
@@ -341,6 +343,7 @@ border-color:#3a2c22;color:#f3e9dc}button{background:#e9b97c;color:#2a1a10}}
|
||||
self._send_json(HTTPStatus.OK, queries.list_videos(
|
||||
sort=_param(query, "sort", "heat"),
|
||||
within_days=_optional_int(query, "within_days"),
|
||||
year=_year_param(query),
|
||||
growth_days=_int_param(query, "growth_days", 7, 1, 365),
|
||||
folder_id=_optional_int(query, "folder"),
|
||||
q=_optional_str(query, "q"),
|
||||
@@ -356,6 +359,7 @@ border-color:#3a2c22;color:#f3e9dc}button{background:#e9b97c;color:#2a1a10}}
|
||||
self._send_json(HTTPStatus.OK, queries.list_ups(
|
||||
sort=_param(query, "sort", "efficiency"),
|
||||
within_days=_optional_int(query, "within_days"),
|
||||
year=_year_param(query),
|
||||
q=_optional_str(query, "q"),
|
||||
min_videos=_int_param(query, "min_videos", 1, 1, 10000),
|
||||
page=_int_param(query, "page", 1, 1, 1_000_000),
|
||||
@@ -526,6 +530,15 @@ def _optional_int(query: Mapping[str, list[str]], name: str) -> int | None:
|
||||
raise ApiError(HTTPStatus.BAD_REQUEST, "bad_request", f"{name} 必须是整数") from exc
|
||||
|
||||
|
||||
def _year_param(query: Mapping[str, list[str]]) -> int | None:
|
||||
value = _optional_int(query, "year")
|
||||
if value is None:
|
||||
return None
|
||||
if value < 2000 or value > 2100:
|
||||
raise ApiError(HTTPStatus.BAD_REQUEST, "bad_request", "year 必须在 2000~2100 之间")
|
||||
return value
|
||||
|
||||
|
||||
def _int_param(
|
||||
query: Mapping[str, list[str]],
|
||||
name: str,
|
||||
|
||||
Reference in new issue
Block a user