add doom scroll
This commit is contained in:
@@ -2,10 +2,11 @@ from pathlib import Path
|
||||
from fastapi import APIRouter, BackgroundTasks, Depends, HTTPException
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.orm import selectinload
|
||||
|
||||
from app.database import get_db
|
||||
from app.models import Library, MediaItem
|
||||
from app.schemas import LibraryCreate, LibraryOut, BrowseResult, BrowseEntry
|
||||
from app.schemas import LibraryCreate, LibraryOut, MediaItemOut, BrowseResult, BrowseEntry
|
||||
from app.services import scanner, watcher as watcher_service
|
||||
|
||||
router = APIRouter(prefix="/libraries", tags=["libraries"])
|
||||
@@ -63,6 +64,28 @@ async def rescan_library(
|
||||
return {"scanning": True}
|
||||
|
||||
|
||||
@router.get("/{library_id}/doom-scroll", response_model=list[MediaItemOut])
|
||||
async def doom_scroll(
|
||||
library_id: int,
|
||||
path: str = "",
|
||||
db: AsyncSession = Depends(get_db),
|
||||
):
|
||||
result = await db.execute(select(Library).where(Library.id == library_id))
|
||||
if not result.scalars().first():
|
||||
raise HTTPException(404, "Library not found")
|
||||
|
||||
stmt = (
|
||||
select(MediaItem)
|
||||
.options(selectinload(MediaItem.tags))
|
||||
.where(MediaItem.library_id == library_id, MediaItem.missing == False) # noqa: E712
|
||||
)
|
||||
if path:
|
||||
stmt = stmt.where(MediaItem.rel_path.like(path + "/%"))
|
||||
|
||||
result = await db.execute(stmt)
|
||||
return result.scalars().all()
|
||||
|
||||
|
||||
@router.delete("/{library_id}", status_code=204)
|
||||
async def delete_library(library_id: int, db: AsyncSession = Depends(get_db)):
|
||||
result = await db.execute(select(Library).where(Library.id == library_id))
|
||||
|
||||
Reference in New Issue
Block a user