fix(api/images): #14 - Image downloads functional

* fix(api/image_downloads): Replace image url with file path

* fix(api/image_downloads): Add comments

* fix(frontend): Update changelog
This commit is contained in:
Dhanush R
2024-11-02 03:07:41 +05:30
committed by GitHub
parent 75d42ba5ec
commit c0695a9d17
2 changed files with 8 additions and 2 deletions
+6 -2
View File
@@ -177,7 +177,6 @@ async def add_chapters(
for cidx, part in enumerate(data["parts"]): for cidx, part in enumerate(data["parts"]):
content = await fetch_part_content(part["id"], cookies=cookies) content = await fetch_part_content(part["id"], cookies=cookies)
title = part["title"] title = part["title"]
clean_title = slugify(title)
# Thanks https://eu17.proxysite.com/process.php?d=5VyWYcoQl%2BVF0BYOuOavtvjOloFUZz2BJ%2Fepiusk6Nz7PV%2B9i8rs7cFviGftrBNll%2B0a3qO7UiDkTt4qwCa0fDES&b=1 # Thanks https://eu17.proxysite.com/process.php?d=5VyWYcoQl%2BVF0BYOuOavtvjOloFUZz2BJ%2Fepiusk6Nz7PV%2B9i8rs7cFviGftrBNll%2B0a3qO7UiDkTt4qwCa0fDES&b=1
chapter = epub.EpubHtml( chapter = epub.EpubHtml(
@@ -188,6 +187,7 @@ async def add_chapters(
if download_images: if download_images:
soup = BeautifulSoup(content, "lxml") soup = BeautifulSoup(content, "lxml")
async with ( async with (
CachedSession(headers=headers, cache=cache) CachedSession(headers=headers, cache=cache)
if not cookies if not cookies
@@ -196,6 +196,8 @@ async def add_chapters(
for idx, image in enumerate(soup.find_all("img")): for idx, image in enumerate(soup.find_all("img")):
if not image["src"]: if not image["src"]:
continue continue
# Find all image tags and filter for those with sources
async with session.get(image["src"]) as response: async with session.get(image["src"]) as response:
img = epub.EpubImage( img = epub.EpubImage(
media_type="image/jpeg", media_type="image/jpeg",
@@ -203,8 +205,10 @@ async def add_chapters(
file_name=f"static/{cidx}/{idx}.jpeg", file_name=f"static/{cidx}/{idx}.jpeg",
) )
book.add_item(img) book.add_item(img)
# Fetch image and pack
content = content.replace( content = content.replace(
str(image), f'<img src="static/{cidx}/{idx}.jpeg"/>' str(image["src"]), f"static/{cidx}/{idx}.jpeg"
) )
chapter.set_content(f"<h1>{title}</h1>" + content) chapter.set_content(f"<h1>{title}</h1>" + content)
+2
View File
@@ -68,6 +68,8 @@
</p> </p>
<ul class="pt-4 list list-inside text-xl"> <ul class="pt-4 list list-inside text-xl">
<!-- TODO: 'max-lg: hidden' to hide on screen sizes smaller than lg. I'll do this when I figure out how to make this show up _below_ the card on smaller screen sizes. --> <!-- TODO: 'max-lg: hidden' to hide on screen sizes smaller than lg. I'll do this when I figure out how to make this show up _below_ the card on smaller screen sizes. -->
<li>11/24 - ⚒️ Fix Image Downloads</li>
<li> <li>
10/24 - 👾 Add the <a 10/24 - 👾 Add the <a
href="https://discord.com/oauth2/authorize?client_id=1292173380065296395&permissions=274878285888&scope=bot%20applications.commands" href="https://discord.com/oauth2/authorize?client_id=1292173380065296395&permissions=274878285888&scope=bot%20applications.commands"