diff --git a/src/api/src/create_book.py b/src/api/src/create_book.py index a871bda..16fcb41 100644 --- a/src/api/src/create_book.py +++ b/src/api/src/create_book.py @@ -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) diff --git a/src/api/src/main.py b/src/api/src/main.py index fec5dd5..cc48579 100644 --- a/src/api/src/main.py +++ b/src/api/src/main.py @@ -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"