Don't schedule cleanup until after compression

Returns uncompressed file if compression somehow fails
This commit is contained in:
Sage Vaillancourt 2021-08-01 00:12:22 -04:00
parent 38fdfc1e90
commit 924bdbd8ce
1 changed files with 9 additions and 2 deletions

View File

@ -63,7 +63,6 @@ class CLData():
if result.returncode == 0:
print(build_text + "[SUCCESS]")
threading.Timer(60 * 5, cleanup, [output_dir + unique_id]).start()
compress_com = "gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.5 -dNOPAUSE -dQUIET -dBATCH -dPrinted=false -sOutputFile=outputs/" + unique_id + ".compressed.pdf outputs/" + unique_id + ".pdf"
result = subprocess.run(
@ -72,9 +71,17 @@ class CLData():
text=True
)
threading.Timer(60 * 5, cleanup, [output_dir + unique_id]).start()
output_file = unique_id
if result.returncode == 0:
output_file += ".compressed.pdf"
else:
output_file += ".pdf"
return (send_from_directory(
output_dir,
unique_id + ".compressed.pdf",
output_file,
attachment_filename=self.username.replace(" ", "") + "_CoverLetter.pdf",
as_attachment=True
), None)