27 lines
890 B
Python
27 lines
890 B
Python
import http.server
|
|
import socketserver
|
|
import os
|
|
import json
|
|
|
|
PORT = 8000
|
|
os.chdir(os.path.dirname(__file__))
|
|
|
|
class CustomHandler(http.server.SimpleHTTPRequestHandler):
|
|
def do_GET(self):
|
|
if self.path == '/list-maps':
|
|
try:
|
|
files = os.listdir('standard_maps')
|
|
image_files = [f for f in files if f.lower().endswith(('.png', '.jpg', '.jpeg'))]
|
|
self.send_response(200)
|
|
self.send_header('Content-Type', 'application/json')
|
|
self.end_headers()
|
|
self.wfile.write(json.dumps(image_files).encode('utf-8'))
|
|
except Exception as e:
|
|
self.send_error(500, f"Fehler: {str(e)}")
|
|
else:
|
|
super().do_GET()
|
|
|
|
with socketserver.TCPServer(("", PORT), CustomHandler) as httpd:
|
|
print(f"Starte Server auf Port {PORT}...")
|
|
httpd.serve_forever()
|