diff --git a/backend/peer_notes/settings.py b/backend/peer_notes/settings.py index cbaefc6..2b2c292 100644 --- a/backend/peer_notes/settings.py +++ b/backend/peer_notes/settings.py @@ -25,7 +25,7 @@ SECRET_KEY = "django-insecure-rh0s*u8$uugtt10cxbifjriaz%@&p1w!)c2=y^undd2*nx5 # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -ALLOWED_HOSTS = ["10.20.4.109", "73.7.29.136", "localhost", "127.0.0.1", "http://localhost:5173"] +ALLOWED_HOSTS = ["*"] # ALLOWED_HOSTS = [] diff --git a/file_peer/peer_service.py b/file_peer/peer_service.py index 602f5f0..f3359b5 100644 --- a/file_peer/peer_service.py +++ b/file_peer/peer_service.py @@ -1,9 +1,22 @@ from flask import Flask, send_file, request import requests +import socket import os app = Flask(__name__) +@app.route('/ip', methods=["GET"]) +def get_internal_ip(): + internal_ip = None + try: + s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + s.connect(("8.8.8.8", 80)) + internal_ip = s.getsockname()[0] + s.close() + except Exception as e: + print("Error:", e) + return internal_ip, 200 + @app.route('/send', methods=['GET']) def send(): file_id = request.args.get('id') @@ -32,13 +45,8 @@ def request_file(): if response.status_code == 200: if os.path.exists(file_path): - # If it does, generate a new filename - i = 1 - beg, end = file_path.split('.') - while os.path.exists(f'{beg}_{i}.{end}'): - i += 1 - file_path = f'{beg}_{i}.{end}' - print("File with name already exists") + + return "File with name already exists", 200 with open(file_path, 'wb') as f: f.write(response.content) @@ -51,4 +59,4 @@ def request_file(): if __name__ == '__main__': - app.run(debug=True, port=8080) + app.run(debug=True, host= '0.0.0.0', port=8080)