Fix: use temp dir for split / merge (#7105)

This commit is contained in:
shamoon 2024-06-26 10:46:59 -07:00 committed by GitHub
parent f3b7ae93f0
commit f3cf608caa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2,6 +2,7 @@ import hashlib
import itertools import itertools
import logging import logging
import os import os
import tempfile
from typing import Optional from typing import Optional
from celery import chain from celery import chain
@ -269,7 +270,7 @@ def merge(
return "OK" return "OK"
filepath = os.path.join( filepath = os.path.join(
settings.SCRATCH_DIR, tempfile.mkdtemp(dir=settings.SCRATCH_DIR),
f"{'_'.join([str(doc_id) for doc_id in doc_ids])[:100]}_merged.pdf", f"{'_'.join([str(doc_id) for doc_id in doc_ids])[:100]}_merged.pdf",
) )
merged_pdf.remove_unreferenced_resources() merged_pdf.remove_unreferenced_resources()
@ -321,7 +322,7 @@ def split(doc_ids: list[int], pages: list[list[int]], delete_originals: bool = F
for page in split_doc: for page in split_doc:
dst.pages.append(pdf.pages[page - 1]) dst.pages.append(pdf.pages[page - 1])
filepath = os.path.join( filepath = os.path.join(
settings.SCRATCH_DIR, tempfile.mkdtemp(dir=settings.SCRATCH_DIR),
f"{doc.id}_{split_doc[0]}-{split_doc[-1]}.pdf", f"{doc.id}_{split_doc[0]}-{split_doc[-1]}.pdf",
) )
dst.remove_unreferenced_resources() dst.remove_unreferenced_resources()