update
This commit is contained in:
@ -1,22 +1,22 @@
|
|||||||
{
|
{
|
||||||
"ID": 0,
|
"ID": "0",
|
||||||
"location": "izba",
|
"location": "izba",
|
||||||
"descrpition": {
|
"description": {
|
||||||
"title": "legionrpi",
|
"title": "legionrpi",
|
||||||
"description_s": "krátky popis, ktorý bude zobrazený iba v náhladovom okne",
|
"description_s": "krátky popis, ktorý bude zobrazený iba v náhladovom okne",
|
||||||
"description_l": "dlhší popis zariadenia, ktorý bude zobrazený po otvorení",
|
"description_l": "dlhší popis zariadenia, ktorý bude zobrazený po otvorení",
|
||||||
"photo_s": "mala_fotka.png",
|
"photo_s": "mala_fotka.png",
|
||||||
"photo_b": "velka fotka.png"
|
"photo_b": "velka fotka.png"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
{
|
{
|
||||||
"name": "test",
|
"name": "test",
|
||||||
"format": ".jpg",
|
"format": ".jpg",
|
||||||
"description": "toto je jpg test file"
|
"description": "toto je jpg test file"
|
||||||
}, {
|
}, {
|
||||||
"name": "test2",
|
"name": "test2",
|
||||||
"format": ".txt",
|
"format": ".txt",
|
||||||
"description": "toto je txt test file"
|
"description": "toto je txt test file"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,15 @@
|
|||||||
from fastapi import FastAPI, Request
|
import hashlib
|
||||||
from fastapi.responses import FileResponse, HTMLResponse
|
|
||||||
from pydantic import BaseModel
|
|
||||||
import engine
|
|
||||||
import requests
|
|
||||||
import time
|
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import threading
|
import threading
|
||||||
import hashlib
|
import time
|
||||||
|
import engine
|
||||||
|
import requests
|
||||||
|
import uuid
|
||||||
|
from fastapi import FastAPI, Request
|
||||||
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
|
from fastapi.responses import FileResponse
|
||||||
|
from pydantic import BaseModel
|
||||||
|
|
||||||
with open("settings.json", "r") as f: # loading settings
|
with open("settings.json", "r") as f: # loading settings
|
||||||
settings = json.load(f)
|
settings = json.load(f)
|
||||||
@ -21,6 +23,16 @@ location = settings["location"]
|
|||||||
time_to_save = settings["time_to_save"]
|
time_to_save = settings["time_to_save"]
|
||||||
|
|
||||||
app = FastAPI() # init of FastAPI
|
app = FastAPI() # init of FastAPI
|
||||||
|
|
||||||
|
origins = ["*", ]
|
||||||
|
app.add_middleware(
|
||||||
|
CORSMiddleware,
|
||||||
|
allow_origins=["*"],
|
||||||
|
allow_credentials=True,
|
||||||
|
allow_methods=["*"],
|
||||||
|
allow_headers=["*"],
|
||||||
|
)
|
||||||
|
|
||||||
log = engine.Log(settings["log"]) # init of LOG
|
log = engine.Log(settings["log"]) # init of LOG
|
||||||
update = engine.Update()
|
update = engine.Update()
|
||||||
offline = []
|
offline = []
|
||||||
@ -39,6 +51,8 @@ sensors = { # List of "live" data like tempeature, etc.
|
|||||||
"doba čakania": 2
|
"doba čakania": 2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
messages = []
|
||||||
|
|
||||||
heartbeat_table["ID"].append(ID)
|
heartbeat_table["ID"].append(ID)
|
||||||
heartbeat_table["IP"].append(IP)
|
heartbeat_table["IP"].append(IP)
|
||||||
heartbeat_table["location"].append(location)
|
heartbeat_table["location"].append(location)
|
||||||
@ -46,8 +60,6 @@ heartbeat_table["file_system"].append(filesystem)
|
|||||||
heartbeat_table["last_heartbeat"].append(time_to_heartbeat)
|
heartbeat_table["last_heartbeat"].append(time_to_heartbeat)
|
||||||
|
|
||||||
|
|
||||||
# Todo better "host" ID handeling
|
|
||||||
|
|
||||||
class ServerTable(BaseModel): # table of content for heartbeat request
|
class ServerTable(BaseModel): # table of content for heartbeat request
|
||||||
ID: list
|
ID: list
|
||||||
IP: list
|
IP: list
|
||||||
@ -56,6 +68,11 @@ class ServerTable(BaseModel): # table of content for heartbeat request
|
|||||||
last_heartbeat: list
|
last_heartbeat: list
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/")
|
||||||
|
def read_root():
|
||||||
|
return {"Hello": "World"}
|
||||||
|
|
||||||
|
|
||||||
@app.post("/heartbeat")
|
@app.post("/heartbeat")
|
||||||
def heartbeat(s_table: ServerTable, request: Request):
|
def heartbeat(s_table: ServerTable, request: Request):
|
||||||
log.message(f"server requested heartbeat {request.client.host}:{request.client.port}")
|
log.message(f"server requested heartbeat {request.client.host}:{request.client.port}")
|
||||||
@ -141,7 +158,7 @@ def comparision(file: str):
|
|||||||
|
|
||||||
@app.get("/devices_list")
|
@app.get("/devices_list")
|
||||||
def get_devices_list():
|
def get_devices_list():
|
||||||
return heartbeat_table["file_system"]
|
return [{"connected_id": ID}, *heartbeat_table["file_system"]]
|
||||||
|
|
||||||
|
|
||||||
@app.get("/admin/{command}")
|
@app.get("/admin/{command}")
|
||||||
@ -152,6 +169,25 @@ def admin(command: str):
|
|||||||
os.system(f"""python3 system.py update -version {command.split("-")[1]}""")
|
os.system(f"""python3 system.py update -version {command.split("-")[1]}""")
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/messages/get")
|
||||||
|
def get_messages(m_from: int = 0, m_to: int = 10):
|
||||||
|
return messages[m_from:m_to]
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/messages/reqister")
|
||||||
|
def get_messages():
|
||||||
|
return uuid.uuid4().hex[24:]
|
||||||
|
|
||||||
|
|
||||||
|
@app.post("/messages/post")
|
||||||
|
def get_messages(m_sender: str = None, message: str = None):
|
||||||
|
if m_sender and message:
|
||||||
|
messages.append({"sender": m_sender, "message": message})
|
||||||
|
return "successfull"
|
||||||
|
else:
|
||||||
|
return "Empty message/sender"
|
||||||
|
|
||||||
|
|
||||||
def send_heartbeat(ip, id):
|
def send_heartbeat(ip, id):
|
||||||
global heartbeat_table
|
global heartbeat_table
|
||||||
log.message(f"""sending heartbeat to {ip}({"offline" if id in offline else "online"})""")
|
log.message(f"""sending heartbeat to {ip}({"offline" if id in offline else "online"})""")
|
||||||
@ -187,7 +223,8 @@ def mainloop():
|
|||||||
log.message(f"""{heartbeat_table["IP"][device_number]} gone online""")
|
log.message(f"""{heartbeat_table["IP"][device_number]} gone online""")
|
||||||
heartbeat_table["last_heartbeat"][int(device_number)] = int(time_to_heartbeat) + 5
|
heartbeat_table["last_heartbeat"][int(device_number)] = int(time_to_heartbeat) + 5
|
||||||
try:
|
try:
|
||||||
log.debug(f"""{device_ID} : time to heartbeat : {heartbeat_table["last_heartbeat"][device_number]}""")
|
log.debug(
|
||||||
|
f"""{device_ID} : time to heartbeat : {heartbeat_table["last_heartbeat"][device_number]}""")
|
||||||
heartbeat_table["last_heartbeat"][device_number] -= 1
|
heartbeat_table["last_heartbeat"][device_number] -= 1
|
||||||
except IndexError:
|
except IndexError:
|
||||||
pass
|
pass
|
||||||
@ -204,5 +241,4 @@ def mainloop():
|
|||||||
thread_1 = threading.Thread(target=mainloop, daemon=True)
|
thread_1 = threading.Thread(target=mainloop, daemon=True)
|
||||||
thread_1.start()
|
thread_1.start()
|
||||||
|
|
||||||
# Todo new filesystem handeling
|
# Todo settings for easy adding/editing files/id/text
|
||||||
# Todo settings for easy adding/editing files/id/text
|
|
||||||
|
BIN
server/server.zip
Normal file
BIN
server/server.zip
Normal file
Binary file not shown.
@ -4,6 +4,8 @@
|
|||||||
"location": "izba",
|
"location": "izba",
|
||||||
"time_to_heartbeat": 20,
|
"time_to_heartbeat": 20,
|
||||||
"time_to_heartbeat_offline": 25,
|
"time_to_heartbeat_offline": 25,
|
||||||
|
"save_table": false,
|
||||||
|
"time_to_save": 60,
|
||||||
"log": {
|
"log": {
|
||||||
"save_error": true,
|
"save_error": true,
|
||||||
"print_error": true,
|
"print_error": true,
|
||||||
@ -19,5 +21,5 @@
|
|||||||
"location": [],
|
"location": [],
|
||||||
"file_system": [],
|
"file_system": [],
|
||||||
"last_heartbeat": []
|
"last_heartbeat": []
|
||||||
}
|
}
|
||||||
}
|
}
|
24
server/test.py
Normal file
24
server/test.py
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import threading
|
||||||
|
import uuid
|
||||||
|
import time
|
||||||
|
|
||||||
|
zoznam = []
|
||||||
|
rovnake = 0
|
||||||
|
run = True
|
||||||
|
start = time.time()
|
||||||
|
|
||||||
|
def generate():
|
||||||
|
global zoznam, rovnake, run
|
||||||
|
while run:
|
||||||
|
cache = uuid.uuid4().hex[24:]
|
||||||
|
if cache in zoznam:
|
||||||
|
rovnake += 1
|
||||||
|
zoznam.append(cache)
|
||||||
|
pocet = len(zoznam)
|
||||||
|
print(f"{pocet} : {rovnake} rovnakých - {cache}")
|
||||||
|
if pocet > 50000:
|
||||||
|
break
|
||||||
|
|
||||||
|
|
||||||
|
generate()
|
||||||
|
print(f"process lasted {time.time()-start}")
|
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"version": "0.5",
|
"version": "0.6",
|
||||||
"id": 3,
|
"id": 4,
|
||||||
"url": "https://raw.githubusercontent.com/UntriexTv/test_directory/main/ver.json"
|
"url": "https://raw.githubusercontent.com/UntriexTv/test_directory/main/ver.json"
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user