Merge 99c7744e4fe2337469254248427b1419e523ac86 into 1b47ca07ef43a284e0b8bd7f29d3e1e3ff76082a

This commit is contained in:
Anupam Mediratta 2026-10-11 08:46:21 -07:00 committed by GitHub
commit f7d2291730
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

20
api.py
View File

@ -1341,24 +1341,38 @@ async def control(command: str = None):
return handle_control(command)
def _is_safe_path(path: str) -> bool:
if not path:
return True
return ".." not in os.path.normpath(path).split(os.sep)
@app.post("/change_refer")
async def change_refer(request: Request):
json_post_raw = await request.json()
refer_wav_path = json_post_raw.get("refer_wav_path")
if not _is_safe_path(refer_wav_path):
return JSONResponse({"code": 400, "message": "Invalid file path"}, status_code=400)
return handle_change(
json_post_raw.get("refer_wav_path"), json_post_raw.get("prompt_text"), json_post_raw.get("prompt_language")
refer_wav_path, json_post_raw.get("prompt_text"), json_post_raw.get("prompt_language")
)
@app.get("/change_refer")
async def change_refer(refer_wav_path: str = None, prompt_text: str = None, prompt_language: str = None):
if not _is_safe_path(refer_wav_path):
return JSONResponse({"code": 400, "message": "Invalid file path"}, status_code=400)
return handle_change(refer_wav_path, prompt_text, prompt_language)
@app.post("/")
async def tts_endpoint(request: Request):
json_post_raw = await request.json()
refer_wav_path = json_post_raw.get("refer_wav_path")
if not _is_safe_path(refer_wav_path):
return JSONResponse({"code": 400, "message": "Invalid file path"}, status_code=400)
return handle(
json_post_raw.get("refer_wav_path"),
refer_wav_path,
json_post_raw.get("prompt_text"),
json_post_raw.get("prompt_language"),
json_post_raw.get("text"),
@ -1392,6 +1406,8 @@ async def tts_endpoint(
if_sr: bool = False,
cfg_rate: float = None,
):
if not _is_safe_path(refer_wav_path):
return JSONResponse({"code": 400, "message": "Invalid file path"}, status_code=400)
return handle(
refer_wav_path,
prompt_text,