From 2be2eee1578ec76879e3336d4d066a16fc896451 Mon Sep 17 00:00:00 2001 From: Brett Date: Sat, 21 Oct 2023 18:03:50 -0700 Subject: [PATCH] Add system_safe_path to more locations in api_server.py --- src/api_server.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/api_server.py b/src/api_server.py index 9489fea..ff05c12 100755 --- a/src/api_server.py +++ b/src/api_server.py @@ -7,6 +7,7 @@ import platform import shutil import socket import ssl +import tempfile import threading import time import zipfile @@ -55,7 +56,7 @@ def sorted_jobs(all_jobs, sort_by_date=True): @server.route('/') @server.route('/index') def index(): - with open('config/presets.yaml') as f: + with open(system_safe_path('config/presets.yaml')) as f: render_presets = yaml.load(f, Loader=yaml.FullLoader) return render_template('index.html', all_jobs=sorted_jobs(RenderQueue.all_jobs()), @@ -189,7 +190,7 @@ def get_job_status(job_id): @server.get('/api/job//logs') def get_job_logs(job_id): found_job = RenderQueue.job_with_id(job_id) - log_path = found_job.log_path() + log_path = system_safe_path(found_job.log_path()), log_data = None if log_path and os.path.exists(log_path): with open(log_path) as file: @@ -233,10 +234,11 @@ def download_all(job_id): found_job = RenderQueue.job_with_id(job_id) output_dir = os.path.dirname(found_job.output_path) if os.path.exists(output_dir): - zip_filename = os.path.join('/tmp', pathlib.Path(found_job.input_path).stem + '.zip') + zip_filename = system_safe_path(os.path.join(tempfile.gettempdir(), + pathlib.Path(found_job.input_path).stem + '.zip')) with ZipFile(zip_filename, 'w') as zipObj: for f in os.listdir(output_dir): - zipObj.write(filename=os.path.join(output_dir, f), + zipObj.write(filename=system_safe_path(os.path.join(output_dir, f)), arcname=os.path.basename(f)) return send_file(zip_filename, mimetype="zip", as_attachment=True, ) else: @@ -585,7 +587,7 @@ def start_server(background_thread=False): RenderQueue.evaluate_queue() time.sleep(delay_sec) - with open('config/config.yaml') as f: + with open(system_safe_path('config/config.yaml')) as f: config = yaml.load(f, Loader=yaml.FullLoader) logging.basicConfig(format='%(asctime)s: %(levelname)s: %(module)s: %(message)s', datefmt='%d-%b-%y %H:%M:%S',