mirror of
https://github.com/ajurna/cbwebreader.git
synced 2026-11-02 18:46:53 +00:00
- Removed `flake8` and `flake8-annotations` from dependencies, replaced by `ruff` for linting. - Introduced cleaner type hinting and modern Python annotations (PEP 604 style) across multiple modules. - Moved archive processing to a dedicated helper (`comic.archives`) for improved maintainability. - Updated and simplified logic for archive file retrieval, directory cleaning, and user access validation. - Improved error handling and added support for user classification restrictions in API responses.
31 lines
881 B
Python
31 lines
881 B
Python
"""Shared helpers for listing the pages inside a comic archive."""
|
|
|
|
import mimetypes
|
|
import zipfile
|
|
from typing import NamedTuple
|
|
|
|
import rarfile
|
|
|
|
|
|
class ArchiveFile(NamedTuple):
|
|
file_name: str
|
|
mime_type: str
|
|
|
|
|
|
def get_archive_files(archive: zipfile.ZipFile | rarfile.RarFile) -> list[ArchiveFile]:
|
|
"""Return the image entries of an archive in page order.
|
|
|
|
Metadata entries such as ComicInfo.xml are not pages. Counting them would make
|
|
page_count disagree with the page list the reader uses, so a book could never
|
|
be marked as finished.
|
|
"""
|
|
result = []
|
|
for name in sorted(archive.namelist()):
|
|
if name.endswith('/'):
|
|
continue
|
|
mime_type = mimetypes.guess_type(name)[0]
|
|
if not mime_type or name.lower().endswith('.xml'):
|
|
continue
|
|
result.append(ArchiveFile(name, mime_type))
|
|
return result
|