mirror of
https://github.com/ajurna/cbwebreader.git
synced 2025-12-06 22:27:19 +00:00
* frontend rewrite with vie initial commit * got ComicCard.vue working nice. * got TheComicList.vue working. * added router and basic config * getting jwt stuff working. * login with jwt now working. * implemented browse api call * implemented browse api recievers * jwt token is now updating automatically. * removed code for jwt testing. * enabled browsing * breadcrumbs working * adding django webpack loader * linking up navigation * fixes for ComicCard.vue stying * added thumbnail view * added thumbnail generation and handling. * detached breadcrumbs * fix breadcrumbs * added first stages of reader * reader view is working. * reader is now working with keyboard shortcuts * implemented setting read page. * implemented pagination on comic reader. * hide elements that shouldn't be shown. * fixed the ComicCard.vue to use as little space as possible. * fix navbar browse link * added RecentView.vue and added manual option for breadcrumbs * updated rest api to handle recent comics. * most functionality of recent comics done * modified comicstatus relation to use uuid relation and implemented mark read and unread for batches. * added functions to TheRecentTable.vue * added feed link to TheRecentTable.vue * fixes for comicstatus updates. * added constraints to comicstatus * update to python packages. * some changes for django 4, also removed django-recaptcha2 as it doesnt support django 4. * some fixes and updates to ComicCard.vue * cleaned up generate_directory. fixed bug where pages not visible on first call. * cleaned up generate_directory. fixed bug where pages not visible on first call. * cleaned up generate_directory. fixed bug where pages not visible on first call. * cleaned up generate_directory. * added silk stubs * fix for re-requesting thumbnail after getting it already. * fix for removing stale comics. adding leeway to access token. * mark read and unread * added filtering to comic list. * stored filtering state. * stored filtering state. * added next functionality to login. * cleanup LoginView.vue * bump font-awesome. * working on AccountView.vue * fixed form submission on LoginView.vue * account page should now be working. * hide users option if not superuser. * added pdf support * make pdf resize. * added touch controls to pdf reader * added touch controls to comic reader * beginnings of routing between issues. * fixes for navigating pages. * fixes for navigating pages. * fixes for navigating pages. * renamed HomeView.vue to BrowseView.vue * stubs for users page added. api ready * users page further functinality * fix for notification * fix for notification * moved messages to parent. * form to add users * added error handling * removed console logging * classification in base directory should be lowest * renamed usermisc to classification to be more consistent with what it does. * renamed usermisc to classification to be more consistent with what it does. * added functionality to change classification of directories. * merged rss_id api into account api. * merged breadcrumbs api into browse api. * clears some warnings from console. * fixed read/unread rendering. * added build script and starting lint * fixing lint errors * fixing lint errors * fixing lint errors * fixing lint errors * fixing lint errors * fixing lint errors * fixing lint errors * fixing lint errors * fixing navigation bugs * cleanup and fixes * fixed generated tooltips over calling. * fixed classifications. * initial setup now working * fix navbar branding * fix favicon * added beta build script. * fixes to get ready for production * optimisations for loading new comics. * added loading indicators to TheComicList.vue * lint fixes * made two methods static. may use them elsewhere. * fix for scanning files. * version updates. * fixes for production * fixes for production Co-authored-by: Peter Dwyer <peter.dwyer@clanwilliamhealth.com>
115 lines
4.6 KiB
Python
115 lines
4.6 KiB
Python
from pathlib import Path
|
|
|
|
from PIL import UnidentifiedImageError
|
|
from django.conf import settings
|
|
from django.core.management.base import BaseCommand
|
|
from loguru import logger
|
|
|
|
from comic.models import ComicBook, Directory
|
|
|
|
|
|
class Command(BaseCommand):
|
|
help = "Scan directories to Update Comic DB"
|
|
|
|
def __init__(self):
|
|
super().__init__()
|
|
self.OUTPUT = False
|
|
self.VERIFY_PAGES = False
|
|
|
|
def add_arguments(self, parser):
|
|
parser.add_argument(
|
|
'--out',
|
|
action='store_true',
|
|
help='Output to console',
|
|
)
|
|
parser.add_argument(
|
|
'--verify_pages',
|
|
action='store_true',
|
|
help='Output to console',
|
|
)
|
|
|
|
def handle(self, *args, **options):
|
|
self.VERIFY_PAGES = options.get('verify_pages', False)
|
|
self.OUTPUT = options.get('out', False)
|
|
self.scan_directory()
|
|
|
|
def scan_directory(self, directory=False):
|
|
|
|
"""
|
|
|
|
:type directory: Directory
|
|
"""
|
|
if not directory:
|
|
comic_dir = settings.COMIC_BOOK_VOLUME
|
|
else:
|
|
comic_dir = Path(settings.COMIC_BOOK_VOLUME, directory.path)
|
|
if directory:
|
|
books = ComicBook.objects.filter(directory=directory)
|
|
else:
|
|
books = ComicBook.objects.filter(directory__isnull=True)
|
|
for book in books:
|
|
Path(comic_dir, book.file_name).is_file()
|
|
if not Path(comic_dir, book.file_name).is_file():
|
|
book.delete()
|
|
for file in sorted(comic_dir.glob('*')):
|
|
if file.is_dir():
|
|
if self.OUTPUT:
|
|
logger.info(f"Scanning Directory {file}")
|
|
try:
|
|
if directory:
|
|
next_directory, created = Directory.objects.get_or_create(name=file.name, parent=directory)
|
|
else:
|
|
next_directory, created = Directory.objects.get_or_create(name=file.name, parent__isnull=True)
|
|
except Directory.MultipleObjectsReturned:
|
|
if directory:
|
|
next_directories = Directory.objects.filter(name=file.name, parent=directory)
|
|
else:
|
|
next_directories = Directory.objects.filter(name=file.name, parent__isnull=True)
|
|
next_directories = next_directories.order_by('id')
|
|
next_directory = next_directories.first()
|
|
next_directories.exclude(id=next_directory.id).delete()
|
|
logger.error(f'Duplicate Directory {file}')
|
|
created = False
|
|
if created:
|
|
next_directory.save()
|
|
self.scan_directory(next_directory)
|
|
else:
|
|
if file.suffix.lower() not in settings.SUPPORTED_FILES:
|
|
continue
|
|
if self.OUTPUT:
|
|
logger.info(f"Scanning File {file}")
|
|
try:
|
|
if directory:
|
|
try:
|
|
book = ComicBook.objects.get(file_name=file.name, directory=directory)
|
|
except ComicBook.MultipleObjectsReturned:
|
|
logger.error(f'Duplicate Comic {file}')
|
|
books = ComicBook.objects.filter(file_name=file.name, directory=directory).order_by('id')
|
|
book = books.first()
|
|
extra_books = books.exclude(id=book.id)
|
|
extra_books.delete()
|
|
if book.version == 0:
|
|
book.version = 1
|
|
book.save()
|
|
if self.VERIFY_PAGES:
|
|
logger.info(f'Verifing pages: {book}')
|
|
book.verify_pages()
|
|
else:
|
|
book = ComicBook.objects.get(file_name=file.name, directory__isnull=True)
|
|
if book.version == 0:
|
|
if directory:
|
|
book.directory = directory
|
|
book.version = 1
|
|
book.save()
|
|
if self.VERIFY_PAGES:
|
|
logger.info(f'Verifing pages: {book}')
|
|
book.verify_pages()
|
|
except ComicBook.DoesNotExist:
|
|
book = ComicBook.process_comic_book(file, directory)
|
|
try:
|
|
book.generate_thumbnail()
|
|
except UnidentifiedImageError:
|
|
book.generate_thumbnail(1)
|
|
except:
|
|
pass
|