fix(api): Close and delete temp files

This commit is contained in:
TheOnlyWayUp
2024-12-07 09:32:37 +00:00
parent 96d367da27
commit 5cbef75d19
2 changed files with 8 additions and 2 deletions
+4 -1
View File
@@ -482,7 +482,7 @@ class PDFGenerator:
# self.canvas = Canvas(self.file)
async def add_chapters(self, contents: List[str], download_images: bool = False):
chapters = []
chapters: List[tempfile._TemporaryFileWrapper] = []
for part, content in zip(self.data["parts"], contents):
html = BeautifulSoup(content, features="lxml")
@@ -561,6 +561,9 @@ class PDFGenerator:
)
)
for chapter in chapters:
chapter.file.close()
def dump(self) -> PDFGenerator:
self.file.seek(0)
+4 -1
View File
@@ -182,7 +182,10 @@ async def handle_download(
):
print(title)
book_bytes = book.dump().file.read()
book_file = book.dump().file
book_bytes = book_file.read()
book_file.close()
match format:
case DownloadFormat.epub:
media_type = "application/epub+zip"