avoid incorrect thumbnails
This commit is contained in:
@@ -8,6 +8,7 @@ from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from sqlalchemy import select
|
||||
from app.models import MediaItem
|
||||
from app.database import SessionLocal
|
||||
from app.services.thumbnails import thumbnail_path
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@@ -86,6 +87,11 @@ async def _do_scan(library_id: int, library_path: str, db: AsyncSession) -> None
|
||||
|
||||
if rel in db_items:
|
||||
item = db_items[rel]
|
||||
new_hash = await loop.run_in_executor(None, hash_file, file_path)
|
||||
if item.file_hash != new_hash:
|
||||
item.file_hash = new_hash
|
||||
item.updated_at = datetime.utcnow()
|
||||
thumbnail_path(item.id).unlink(missing_ok=True)
|
||||
if item.missing:
|
||||
item.missing = False
|
||||
item.updated_at = datetime.utcnow()
|
||||
@@ -93,6 +99,7 @@ async def _do_scan(library_id: int, library_path: str, db: AsyncSession) -> None
|
||||
file_hash = await loop.run_in_executor(None, hash_file, file_path)
|
||||
moved = await _find_by_hash(library_id, file_hash, db)
|
||||
if moved:
|
||||
thumbnail_path(moved.id).unlink(missing_ok=True)
|
||||
moved.rel_path = rel
|
||||
moved.filename = file_path.name
|
||||
moved.missing = False
|
||||
@@ -131,4 +138,5 @@ async def _find_by_hash(library_id: int, file_hash: str, db: AsyncSession) -> Me
|
||||
MediaItem.missing == True, # noqa: E712
|
||||
)
|
||||
)
|
||||
return result.scalars().first()
|
||||
rows = result.scalars().all()
|
||||
return rows[0] if len(rows) == 1 else None
|
||||
|
||||
@@ -9,6 +9,7 @@ from sqlalchemy import select
|
||||
from app.database import SessionLocal
|
||||
from app.models import Library, MediaItem
|
||||
from app.services.scanner import classify, hash_file
|
||||
from app.services.thumbnails import thumbnail_path
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@@ -59,6 +60,7 @@ class LibraryEventHandler(FileSystemEventHandler):
|
||||
)
|
||||
item = result.scalars().first()
|
||||
if item:
|
||||
thumbnail_path(item.id).unlink(missing_ok=True)
|
||||
item.rel_path = dest_rel
|
||||
item.filename = Path(event.dest_path).name
|
||||
item.missing = False
|
||||
|
||||
Reference in New Issue
Block a user