This commit is contained in:
2026-05-03 13:12:55 +03:00
parent 07bc7ef1e0
commit 2cb244d973
2 changed files with 112 additions and 51 deletions

View File

@@ -266,7 +266,8 @@ def _format_size(bytes_val: int) -> str:
bytes_val /= 1024
return f"{bytes_val:.1f} ТБ"
def _enrich_manga(m: dict, db: StateDB) -> dict:
size_bytes = _dir_size(_manga_folder(m))
folder = _manga_folder(m)
size_bytes = _dir_size(folder) if (m.get("folder_name") or m.get("title")) else 0
stats = db.get_chapter_stats(m["url"])
source_info = None
if m.get("source_id"):
@@ -678,6 +679,33 @@ async def refresh_meta(url: str, current_user: dict = Depends(get_current_user))
db.close()
asyncio.create_task(_do_refresh_meta(url))
return {"ok": True}
def _patch_meta_sync(manga: dict, chapters: list, chapters_total: int, pub_status: str) -> tuple[int, int]:
updated = failed = 0
url = manga["url"]
for ch in chapters:
for fmt_col in ("output_cbz", "output_pdf", "output_epub"):
fpath = ch.get(fmt_col)
if not fpath:
continue
p = Path(fpath)
if not p.exists():
continue
meta = MangaMeta(
series=manga.get("title_ru") or manga.get("title") or "",
series_full=manga.get("title_full") or "",
chapter_title=ch.get("title") or "",
number=float(ch.get("number") or 0),
volume=int(ch.get("volume") or 0),
chapters_total=chapters_total,
pub_status=pub_status,
source_url=url,
)
if patch_meta(p, meta):
updated += 1
else:
failed += 1
return updated, failed
async def _do_refresh_meta(url: str):
db = StateDB()
try:
@@ -687,36 +715,17 @@ async def _do_refresh_meta(url: str):
chapters = db.get_all_chapters(url)
chapters_total = len(chapters)
pub_status = manga.get("pub_status", "unknown") or "unknown"
updated = failed = 0
for ch in chapters:
for fmt_col, ext in (("output_cbz", ".cbz"), ("output_pdf", ".pdf"), ("output_epub", ".epub")):
fpath = ch.get(fmt_col)
if not fpath:
continue
p = Path(fpath)
if not p.exists():
continue
meta = MangaMeta(
series=manga.get("title_ru") or manga.get("title") or "",
series_full=manga.get("title_full") or "",
chapter_title=ch.get("title") or "",
number=float(ch.get("number") or 0),
volume=int(ch.get("volume") or 0),
chapters_total=chapters_total,
pub_status=pub_status,
source_url=url,
)
if patch_meta(p, meta):
updated += 1
else:
failed += 1
finally:
db.close()
try:
await ws_manager.broadcast({"type": "meta_refresh_started", "url": url})
updated, failed = await asyncio.to_thread(_patch_meta_sync, manga, chapters, chapters_total, pub_status)
logger.info("refresh_meta {}: обновлено {}, ошибок {}", url, updated, failed)
await ws_manager.broadcast({"type": "meta_refreshed", "url": url,
"updated": updated, "failed": failed})
except Exception as e:
logger.error("_do_refresh_meta {}: {}", url, e)
finally:
db.close()
await ws_manager.broadcast({"type": "meta_refreshed", "url": url, "updated": 0, "failed": -1})
class UpdateMetaRequest(BaseModel):
url: str
title_ru: str