add getting image

This commit is contained in:
SemvdH
2025-11-17 23:15:46 +01:00
parent 813cd8c360
commit aa187bf562
2 changed files with 13 additions and 1 deletions

View File

@@ -4,7 +4,7 @@ import json
import dbus
from urllib.parse import parse_qs
from ac_maps import change_track, get_all_tracks, get_configs, get_preview_image, get_outline_image
from ac_cars import get_all_cars
from ac_cars import get_all_cars, get_car_image
class Handler(BaseHTTPRequestHandler):
def do_GET(self):
@@ -57,6 +57,10 @@ class Handler(BaseHTTPRequestHandler):
if img_path == "":
img_path = get_preview_image(track, config)
elif (img_type == "car"):
car = parts[2] if len(parts) > 2 else ""
skin = parts[3] if len(parts) > 3 else ""
img_path = get_car_image(car, skin)
else:
self.send_error(404)
return True

View File

@@ -37,4 +37,12 @@ def get_car_skins(car: str) -> list[str]:
skindirs = [x.path.replace(skin_path + "/","") for x in os.scandir(skin_path) if x.is_dir()]
return skindirs
def get_car_image(car: str, skin: str) -> str:
img_path = os.path.join(CARS_FOLDER, car,"skins", skin)
for name in os.listdir(img_path):
lower = name.lower()
if "preview" in lower and lower.endswith(".png") or lower.endswith(".jpg"):
return os.path.join(img_path, name)
return ""