mirror of
https://github.com/AmanTahiliani/PeerNotes.git
synced 2026-08-07 19:56:19 -04:00
Updated peer service
This commit is contained in:
@@ -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!
|
# SECURITY WARNING: don't run with debug turned on in production!
|
||||||
DEBUG = True
|
DEBUG = True
|
||||||
|
|
||||||
ALLOWED_HOSTS = ["10.20.4.109", "73.7.29.136", "localhost", "127.0.0.1", "http://localhost:5173"]
|
ALLOWED_HOSTS = ["*"]
|
||||||
# ALLOWED_HOSTS = []
|
# ALLOWED_HOSTS = []
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,22 @@
|
|||||||
from flask import Flask, send_file, request
|
from flask import Flask, send_file, request
|
||||||
import requests
|
import requests
|
||||||
|
import socket
|
||||||
import os
|
import os
|
||||||
|
|
||||||
app = Flask(__name__)
|
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'])
|
@app.route('/send', methods=['GET'])
|
||||||
def send():
|
def send():
|
||||||
file_id = request.args.get('id')
|
file_id = request.args.get('id')
|
||||||
@@ -32,13 +45,8 @@ def request_file():
|
|||||||
|
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
if os.path.exists(file_path):
|
if os.path.exists(file_path):
|
||||||
# If it does, generate a new filename
|
|
||||||
i = 1
|
return "File with name already exists", 200
|
||||||
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")
|
|
||||||
|
|
||||||
with open(file_path, 'wb') as f:
|
with open(file_path, 'wb') as f:
|
||||||
f.write(response.content)
|
f.write(response.content)
|
||||||
@@ -51,4 +59,4 @@ def request_file():
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(debug=True, port=8080)
|
app.run(debug=True, host= '0.0.0.0', port=8080)
|
||||||
|
|||||||
Reference in New Issue
Block a user