Files
Athena-Deck/stimmatelier_proxy.py
T

14 lines
838 B
Python

"""Fixed static-asset proxy to the isolated studio container, never forwards credentials."""
import http.client,socket
ASSETS={'/stimmatelier/':('/','text/html; charset=utf-8'),'/stimmatelier/app.js':('/app.js','text/javascript; charset=utf-8'),'/stimmatelier/style.css':('/style.css','text/css; charset=utf-8')}
def asset(path,root):
if path not in ASSETS:raise ValueError('Unbekannte Studio-Datei.')
target,mime=ASSETS[path];conn=http.client.HTTPConnection('localhost',timeout=5)
conn.sock=socket.socket(socket.AF_UNIX,socket.SOCK_STREAM);conn.sock.settimeout(5)
try:
conn.sock.connect(str(root/'stimmatelier-ui/ui.sock'));conn.request('GET',target)
r=conn.getresponse();body=r.read(262145)
if r.status!=200 or len(body)>262144:raise ValueError('Stimmatelier-Datei nicht verfügbar.')
return body,mime
finally:conn.close()