Add loading existing cars on page load. First part of #2

This commit is contained in:
SemvdH
2025-11-21 23:49:06 +01:00
parent 880680871d
commit 808db12e25
3 changed files with 77 additions and 4 deletions

View File

@@ -4,7 +4,7 @@ import json
import dbus
from urllib.parse import parse_qs
from ac_tracks import change_track, get_all_tracks, get_configs, get_preview_image, get_outline_image
from ac_cars import get_all_cars, get_car_image, update_cars
from ac_cars import get_all_cars, get_car_image, update_cars, get_current_cars
class Handler(BaseHTTPRequestHandler):
def do_GET(self):
@@ -35,6 +35,8 @@ class Handler(BaseHTTPRequestHandler):
if self.path == "/cars":
return self.handle_get_cars_path()
if self.path == "/currentcars":
return self.handle_get_current_cars_path()
if self.path == "/" or self.path == "/index.html":
return self.handle_get_root_path()
@@ -99,6 +101,18 @@ class Handler(BaseHTTPRequestHandler):
self.wfile.write(json.dumps(data).encode())
return True
def handle_get_current_cars_path(self):
cars = get_current_cars()
data = {
"cars": cars
}
self.send_response(200)
self.send_header("Content-type", "application/json")
self.end_headers()
self.wfile.write(json.dumps(data).encode())
return True
def handle_get_root_path(self):
with open("index.html", "r") as f:
html = f.read()