From b31b9357cc8b0e8b4eab143166a46913cc8033a3 Mon Sep 17 00:00:00 2001 From: TheFJcurve Date: Wed, 13 Nov 2024 17:24:11 -0500 Subject: [PATCH] even less hardcoding --- backend/code/main.py | 4 ++-- backend/code/p2p_client.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/code/main.py b/backend/code/main.py index e8f38a6..832b40e 100644 --- a/backend/code/main.py +++ b/backend/code/main.py @@ -76,12 +76,12 @@ def receive_token(): print("Could not find the fucking file with file id " + file_hash) return jsonify({"error": "Can't find file hash"}), 400 - file_path = os.path.join('sources', files[1]) + file_path = os.path.join(SOURCES_FOLDER, files[1]) with open(file_path, 'r', encoding="utf-8") as f: file_with_extension = json.loads(f.read())['header']['file_name'] - with open(os.path.join('uploads', file_with_extension), 'rb') as f: + with open(os.path.join(UPLOADS_FOLDER, file_with_extension), 'rb') as f: file_data = f.read() file_blob = io.BytesIO(file_data) diff --git a/backend/code/p2p_client.py b/backend/code/p2p_client.py index 5e110b3..1805fa2 100644 --- a/backend/code/p2p_client.py +++ b/backend/code/p2p_client.py @@ -223,7 +223,7 @@ def listen_for_messages(self): elif message["type"] == "response_block": self.save_block(message) self.tmp_to_file(os.path.join( - 'uploads', Path(message['file_name']).stem + '.tmp')) + UPLOADS_FOLDER, Path(message['file_name']).stem + '.tmp')) else: print("Invalid message type: " + message["type"]) else: @@ -244,7 +244,7 @@ def tmp_to_file(self, tmp_file_path): # print("CONTENT:", content) s = content.values().join() - with open(os.path.join('uploads', file_with_extension), 'w+', encoding="utf-8") as f: + with open(os.path.join(UPLOADS_FOLDER, file_with_extension), 'w+', encoding="utf-8") as f: f.write(s) os.remove(tmp_file_path)