add rescan button
This commit is contained in:
@@ -47,6 +47,22 @@ async def get_scan_status(library_id: int):
|
||||
return {"scanning": scanner.is_scanning(library_id)}
|
||||
|
||||
|
||||
@router.post("/{library_id}/rescan")
|
||||
async def rescan_library(
|
||||
library_id: int,
|
||||
background_tasks: BackgroundTasks,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
):
|
||||
result = await db.execute(select(Library).where(Library.id == library_id))
|
||||
lib = result.scalars().first()
|
||||
if not lib:
|
||||
raise HTTPException(404, "Library not found")
|
||||
if scanner.is_scanning(library_id):
|
||||
raise HTTPException(409, "Scan already in progress")
|
||||
background_tasks.add_task(scanner.scan_library_background, lib.id, lib.path)
|
||||
return {"scanning": True}
|
||||
|
||||
|
||||
@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))
|
||||
@@ -88,7 +104,7 @@ async def browse_library(library_id: int, path: str = "", db: AsyncSession = Dep
|
||||
|
||||
entries: list[BrowseEntry] = []
|
||||
|
||||
for entry in sorted(target.iterdir(), key=lambda e: (e.is_file(), e.name.lower())):
|
||||
for entry in sorted((e for e in target.iterdir() if not e.name.startswith(".")), key=lambda e: (e.is_file(), e.name.lower())):
|
||||
rel_entry = str(entry.relative_to(root))
|
||||
if entry.is_dir():
|
||||
entries.append(BrowseEntry(name=entry.name, type="dir", rel_path=rel_entry))
|
||||
|
||||
Reference in New Issue
Block a user