Add loading current track and config. Second part and fixes #2

This commit is contained in:
SemvdH
2025-11-22 00:35:32 +01:00
parent 808db12e25
commit 15c280b45e
3 changed files with 73 additions and 35 deletions

View File

@@ -3,7 +3,7 @@ import os
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_tracks import change_track, get_all_tracks, get_configs, get_preview_image, get_outline_image, get_current_track
from ac_cars import get_all_cars, get_car_image, update_cars, get_current_cars
class Handler(BaseHTTPRequestHandler):
@@ -37,6 +37,8 @@ class Handler(BaseHTTPRequestHandler):
return self.handle_get_cars_path()
if self.path == "/currentcars":
return self.handle_get_current_cars_path()
if self.path == "/currenttrack":
return self.handle_get_current_track_path()
if self.path == "/" or self.path == "/index.html":
return self.handle_get_root_path()
@@ -88,6 +90,19 @@ class Handler(BaseHTTPRequestHandler):
self.wfile.write(json.dumps(data).encode())
return True
def handle_get_current_track_path(self):
track, config = get_current_track()
data = {
"track": track,
"config": config
}
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_cars_path(self):
cars = get_all_cars()