From 924bdbd8ce178743eee1a784a84467fb85f8d835 Mon Sep 17 00:00:00 2001 From: Sage Vaillancourt Date: Sun, 1 Aug 2021 00:12:22 -0400 Subject: [PATCH] Don't schedule cleanup until after compression Returns uncompressed file if compression somehow fails --- latty.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/latty.py b/latty.py index dfd6798..b29fc47 100644 --- a/latty.py +++ b/latty.py @@ -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)