fix(api): Close and delete temp files
This commit is contained in:
@@ -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
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user