PLUS: банк с CDN (302), проверка API в мониторе туннеля
Browse files- plus/sse_proxy.py +19 -0
plus/sse_proxy.py
CHANGED
|
@@ -188,6 +188,9 @@ HOP_HEADERS = {"connection", "keep-alive", "proxy-authenticate", "proxy-authoriz
|
|
| 188 |
"te", "trailers", "transfer-encoding", "upgrade", "host",
|
| 189 |
"content-length", "accept-encoding"}
|
| 190 |
PING_SECONDS = 10.0
|
|
|
|
|
|
|
|
|
|
| 191 |
|
| 192 |
|
| 193 |
def read_body(handler) -> bytes:
|
|
@@ -243,6 +246,7 @@ class Proxy(BaseHTTPRequestHandler):
|
|
| 243 |
energy_threshold = 6.0
|
| 244 |
refine_articulation = True
|
| 245 |
last_audio: tuple[str, bytes] | None = None
|
|
|
|
| 246 |
|
| 247 |
def log_message(self, fmt, *args):
|
| 248 |
pass
|
|
@@ -266,6 +270,18 @@ class Proxy(BaseHTTPRequestHandler):
|
|
| 266 |
self.pass_through("OPTIONS")
|
| 267 |
|
| 268 |
def pass_through(self, method: str):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 269 |
body = read_body(self)
|
| 270 |
content_type = self.headers.get("Content-Type") or ""
|
| 271 |
audio = guess_audio(body, content_type)
|
|
@@ -472,6 +488,8 @@ def main():
|
|
| 472 |
parser.add_argument("--listen", type=int, default=8223)
|
| 473 |
parser.add_argument("--target", type=int, default=8222)
|
| 474 |
parser.add_argument("--ping", type=float, default=PING_SECONDS)
|
|
|
|
|
|
|
| 475 |
parser.add_argument("--multi-pass", default="",
|
| 476 |
help="второй проход с этим набором инструментов и слияние,"
|
| 477 |
" например: chromatic_percussion,electric_bass,acoustic_bass")
|
|
@@ -488,6 +506,7 @@ def main():
|
|
| 488 |
args = parser.parse_args()
|
| 489 |
Proxy.target_port = args.target
|
| 490 |
Proxy.ping_seconds = args.ping
|
|
|
|
| 491 |
Proxy.measure_velocity = not args.no_velocity
|
| 492 |
Proxy.multi_pass, warning = guard_instruments(
|
| 493 |
expand_instruments(args.multi_pass), "--multi-pass")
|
|
|
|
| 188 |
"te", "trailers", "transfer-encoding", "upgrade", "host",
|
| 189 |
"content-length", "accept-encoding"}
|
| 190 |
PING_SECONDS = 10.0
|
| 191 |
+
# Звуковой банк (38 МБ) не гоняем через туннель: браузер берёт его с CDN.
|
| 192 |
+
FONT_CDN = ("https://huggingface.co/Nokia123543/muscriptor-large-fork"
|
| 193 |
+
"/resolve/main/soundfonts/MuseScore_General.sf3")
|
| 194 |
|
| 195 |
|
| 196 |
def read_body(handler) -> bytes:
|
|
|
|
| 246 |
energy_threshold = 6.0
|
| 247 |
refine_articulation = True
|
| 248 |
last_audio: tuple[str, bytes] | None = None
|
| 249 |
+
font_cdn = os.environ.get("MUSCRIPTOR_FONT_CDN", FONT_CDN)
|
| 250 |
|
| 251 |
def log_message(self, fmt, *args):
|
| 252 |
pass
|
|
|
|
| 270 |
self.pass_through("OPTIONS")
|
| 271 |
|
| 272 |
def pass_through(self, method: str):
|
| 273 |
+
path_only = self.path.split("?")[0]
|
| 274 |
+
if (method in ("GET", "HEAD") and self.font_cdn
|
| 275 |
+
and path_only.startswith("/soundfonts/")
|
| 276 |
+
and "local=1" not in self.path):
|
| 277 |
+
# тяжёлый банк отдаёт CDN, туннель отдыхает
|
| 278 |
+
print("банк: редирект на CDN (%s)" % path_only, flush=True)
|
| 279 |
+
self.send_response(302)
|
| 280 |
+
self.send_header("Location", self.font_cdn)
|
| 281 |
+
self.send_header("Content-Length", "0")
|
| 282 |
+
self.send_header("Cache-Control", "public, max-age=86400")
|
| 283 |
+
self.end_headers()
|
| 284 |
+
return
|
| 285 |
body = read_body(self)
|
| 286 |
content_type = self.headers.get("Content-Type") or ""
|
| 287 |
audio = guess_audio(body, content_type)
|
|
|
|
| 488 |
parser.add_argument("--listen", type=int, default=8223)
|
| 489 |
parser.add_argument("--target", type=int, default=8222)
|
| 490 |
parser.add_argument("--ping", type=float, default=PING_SECONDS)
|
| 491 |
+
parser.add_argument("--font-cdn", default=os.environ.get("MUSCRIPTOR_FONT_CDN", FONT_CDN),
|
| 492 |
+
help="адрес звукового банка на CDN; none — отдавать с сервера")
|
| 493 |
parser.add_argument("--multi-pass", default="",
|
| 494 |
help="второй проход с этим набором инструментов и слияние,"
|
| 495 |
" например: chromatic_percussion,electric_bass,acoustic_bass")
|
|
|
|
| 506 |
args = parser.parse_args()
|
| 507 |
Proxy.target_port = args.target
|
| 508 |
Proxy.ping_seconds = args.ping
|
| 509 |
+
Proxy.font_cdn = "" if (args.font_cdn or "").lower() in ("none", "off", "-") else args.font_cdn
|
| 510 |
Proxy.measure_velocity = not args.no_velocity
|
| 511 |
Proxy.multi_pass, warning = guard_instruments(
|
| 512 |
expand_instruments(args.multi_pass), "--multi-pass")
|