fix(api): Close and delete temp files
This commit is contained in:
@@ -482,7 +482,7 @@ class PDFGenerator:
|
|||||||
# self.canvas = Canvas(self.file)
|
# self.canvas = Canvas(self.file)
|
||||||
|
|
||||||
async def add_chapters(self, contents: List[str], download_images: bool = False):
|
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):
|
for part, content in zip(self.data["parts"], contents):
|
||||||
html = BeautifulSoup(content, features="lxml")
|
html = BeautifulSoup(content, features="lxml")
|
||||||
@@ -561,6 +561,9 @@ class PDFGenerator:
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
for chapter in chapters:
|
||||||
|
chapter.file.close()
|
||||||
|
|
||||||
def dump(self) -> PDFGenerator:
|
def dump(self) -> PDFGenerator:
|
||||||
self.file.seek(0)
|
self.file.seek(0)
|
||||||
|
|
||||||
|
|||||||
+4
-1
@@ -182,7 +182,10 @@ async def handle_download(
|
|||||||
):
|
):
|
||||||
print(title)
|
print(title)
|
||||||
|
|
||||||
book_bytes = book.dump().file.read()
|
book_file = book.dump().file
|
||||||
|
book_bytes = book_file.read()
|
||||||
|
book_file.close()
|
||||||
|
|
||||||
match format:
|
match format:
|
||||||
case DownloadFormat.epub:
|
case DownloadFormat.epub:
|
||||||
media_type = "application/epub+zip"
|
media_type = "application/epub+zip"
|
||||||
|
|||||||
Reference in New Issue
Block a user