From 5b5325f2f6310d85d654f944f73b9206482ac87f Mon Sep 17 00:00:00 2001 From: Untriex Programming Date: Fri, 23 Apr 2021 12:13:46 +0200 Subject: [PATCH] updaTE --- server/log.txt | 4 +++- server/main.py | 18 +++++++++++++----- server/test.py | 11 ++++------- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/server/log.txt b/server/log.txt index 3aa293a..a8deb2b 100644 --- a/server/log.txt +++ b/server/log.txt @@ -160,4 +160,6 @@ 2021-04-22 10:15:53.540044 -> Warning: Address(host='192.168.1.99', port=43642) created new sensor. SENSOR: name='test1' value='juhuu' 2021-04-22 10:16:02.865022 -> Warning: Address(host='192.168.1.99', port=43644) created new sensor. - SENSOR: name='test2' value='eeeh' \ No newline at end of file + SENSOR: name='test2' value='eeeh' +2021-04-23 11:22:54.684617 -> Warning: 192.168.1.231 disconnected/is not available +2021-04-23 11:36:58.295015 -> Warning: 192.168.1.231 disconnected/is not available \ No newline at end of file diff --git a/server/main.py b/server/main.py index 4514300..87002b4 100644 --- a/server/main.py +++ b/server/main.py @@ -239,12 +239,20 @@ def admin_get(command: str): return filesystem -@app.post("/admin/upload_file") -async def create_upload_file(uploaded_file: UploadFile = File(...), patch: str = ""): +@app.post("/admin/{id_server}/upload_file") +async def create_upload_file(id_server: int, uploaded_file: UploadFile = File(...), patch: str = ""): file_location = f"{patch}{uploaded_file.filename}" - with open(file_location, "wb+") as file_object: - file_object.write(uploaded_file.file.read()) - return {"info": f"file '{uploaded_file.filename}' saved at '{file_location}'"} + if id_server == ID: + with open(file_location, "wb+") as file_object: + file_object.write(uploaded_file.file.read()) + else: + with open(f"cache/{uploaded_file.filename}", "wb+") as file_object: + file_object.write(uploaded_file.file.read()) + file = open(f"cache/{uploaded_file.filename}", "r") + requests.post(f"""http://{heartbeat_table["IP"][heartbeat_table["ID"].index(id_server)]}:8000/admin/{id_server}/upload_file""", + files={"uploaded_file": file, "patch": patch}) + file.close() + return {"info": f"""file '{uploaded_file.filename}' saved at '{id_server}/{file_location}'"""} # Todo upload of update file and settings diff --git a/server/test.py b/server/test.py index 83f866d..628105c 100644 --- a/server/test.py +++ b/server/test.py @@ -1,9 +1,6 @@ import requests -import time -send_n = 100 -wait_t = 0.5 -for x in range(send_n): - r = requests.post("http://192.168.1.99:8000/messages/post", json={"m_sender": "server", "message": str(x)}) - print(f"Sent message {x+1}/{send_n}\nResponse: {r.text}") - time.sleep(wait_t) \ No newline at end of file +file = open("files/test.jpg", "r") +r = requests.post(f"""http://192.168.1.99:8000/admin/1/upload_file""", + files={"uploaded_file": file, "patch": ""}) +print(r.text) \ No newline at end of file