Don't schedule cleanup until after compression
Returns uncompressed file if compression somehow fails
This commit is contained in:
parent
38fdfc1e90
commit
924bdbd8ce
11
latty.py
11
latty.py
|
@ -63,7 +63,6 @@ class CLData():
|
||||||
|
|
||||||
if result.returncode == 0:
|
if result.returncode == 0:
|
||||||
print(build_text + "[SUCCESS]")
|
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"
|
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(
|
result = subprocess.run(
|
||||||
|
@ -72,9 +71,17 @@ class CLData():
|
||||||
text=True
|
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(
|
return (send_from_directory(
|
||||||
output_dir,
|
output_dir,
|
||||||
unique_id + ".compressed.pdf",
|
output_file,
|
||||||
attachment_filename=self.username.replace(" ", "") + "_CoverLetter.pdf",
|
attachment_filename=self.username.replace(" ", "") + "_CoverLetter.pdf",
|
||||||
as_attachment=True
|
as_attachment=True
|
||||||
), None)
|
), None)
|
||||||
|
|
Loading…
Reference in New Issue