This commit is contained in:
Untriex Programming 2021-04-23 12:13:46 +02:00
parent a039517975
commit 5b5325f2f6
3 changed files with 20 additions and 13 deletions

@ -161,3 +161,5 @@
SENSOR: name='test1' value='juhuu' SENSOR: name='test1' value='juhuu'
2021-04-22 10:16:02.865022 -> Warning: Address(host='192.168.1.99', port=43644) created new sensor. 2021-04-22 10:16:02.865022 -> Warning: Address(host='192.168.1.99', port=43644) created new sensor.
SENSOR: name='test2' value='eeeh' 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

@ -239,12 +239,20 @@ def admin_get(command: str):
return filesystem return filesystem
@app.post("/admin/upload_file") @app.post("/admin/{id_server}/upload_file")
async def create_upload_file(uploaded_file: UploadFile = File(...), patch: str = ""): async def create_upload_file(id_server: int, uploaded_file: UploadFile = File(...), patch: str = ""):
file_location = f"{patch}{uploaded_file.filename}" file_location = f"{patch}{uploaded_file.filename}"
if id_server == ID:
with open(file_location, "wb+") as file_object: with open(file_location, "wb+") as file_object:
file_object.write(uploaded_file.file.read()) file_object.write(uploaded_file.file.read())
return {"info": f"file '{uploaded_file.filename}' saved at '{file_location}'"} 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 # Todo upload of update file and settings

@ -1,9 +1,6 @@
import requests import requests
import time
send_n = 100
wait_t = 0.5
for x in range(send_n): file = open("files/test.jpg", "r")
r = requests.post("http://192.168.1.99:8000/messages/post", json={"m_sender": "server", "message": str(x)}) r = requests.post(f"""http://192.168.1.99:8000/admin/1/upload_file""",
print(f"Sent message {x+1}/{send_n}\nResponse: {r.text}") files={"uploaded_file": file, "patch": ""})
time.sleep(wait_t) print(r.text)