Fix list truncation
This commit is contained in:
@@ -59,8 +59,29 @@ async def search_media(query: str) -> list[dict]:
|
||||
return [dict(r) for r in rows]
|
||||
|
||||
|
||||
async def list_media() -> list[dict]:
|
||||
return await search_media("")
|
||||
async def list_media(page: int, page_size: int) -> list[dict]:
|
||||
"""Return one page of saved media, newest first."""
|
||||
offset = page * page_size
|
||||
async with aiosqlite.connect(DB_PATH) as db:
|
||||
db.row_factory = aiosqlite.Row
|
||||
cursor = await db.execute(
|
||||
"""
|
||||
SELECT id, file_id, file_unique_id, media_type, keywords
|
||||
FROM media
|
||||
ORDER BY added_at DESC, id DESC
|
||||
LIMIT ? OFFSET ?
|
||||
""",
|
||||
(page_size, offset),
|
||||
)
|
||||
rows = await cursor.fetchall()
|
||||
return [dict(r) for r in rows]
|
||||
|
||||
|
||||
async def count_media() -> int:
|
||||
async with aiosqlite.connect(DB_PATH) as db:
|
||||
cursor = await db.execute("SELECT COUNT(*) FROM media")
|
||||
row = await cursor.fetchone()
|
||||
return row[0]
|
||||
|
||||
|
||||
async def get_media_by_id(media_id: int) -> dict | None:
|
||||
|
||||
Reference in New Issue
Block a user