From 155e60700ff3d77f2b10008bc47bea824aed2339 Mon Sep 17 00:00:00 2001 From: Sahej Panag Date: Sun, 21 Apr 2024 20:23:19 -0400 Subject: [PATCH] test1 again --- file_peer/peer_service.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/file_peer/peer_service.py b/file_peer/peer_service.py index 4bed382..622ac06 100644 --- a/file_peer/peer_service.py +++ b/file_peer/peer_service.py @@ -74,6 +74,37 @@ def request_file(): error = response.text print("Error:", error) return error, response.status_code + +@app.route('/request-tests', methods=['GET']) +def request_tests(): + data = request.json + file_id = data['id'] + filename = data['filename'] + ip = data['ip'] + new_filename = data['new_filename'] + + + url = f"http://{ip}:8080/send" + params = { + 'id': file_id, + 'filename': filename, + } + + response = requests.get(url, params=params) + file_path = './uploads/' + str(file_id) + '_' + new_filename + + if response.status_code == 200: + if os.path.exists(file_path): + return "File with name already exists", 200 + + with open(file_path, 'wb') as f: + f.write(response.content) + print("File downloaded successfully") + return f'File Downloaded to location to location {file_path}', 200 + else: + error = response.text + print("Error:", error) + return error, response.status_code if __name__ == '__main__':