From 2c786421abefb84fc548ae57df172bad07ad5f4d Mon Sep 17 00:00:00 2001 From: tarepan Date: Mon, 6 May 2024 04:38:19 +0900 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E7=90=86:=20`setting=5Fui=5Ftemplate`?= =?UTF-8?q?=20=E3=82=92=E3=83=AB=E3=83=BC=E3=82=BF=E3=83=BC=E3=81=AB?= =?UTF-8?q?=E7=A7=BB=E5=8B=95=20(#1213)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit refactor: `setting_ui_template` をルーターに移動 Co-authored-by: Hiroshiba Kazuyuki --- run.py | 13 +------------ voicevox_engine/app/routers/setting.py | 10 ++++++++-- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/run.py b/run.py index 2ba61d0c9..57fc3467a 100644 --- a/run.py +++ b/run.py @@ -11,7 +11,6 @@ import uvicorn from fastapi import FastAPI, HTTPException from fastapi.responses import HTMLResponse -from fastapi.templating import Jinja2Templates from voicevox_engine import __version__ from voicevox_engine.app.dependencies import deprecated_mutable_api @@ -120,12 +119,6 @@ async def lifespan(app: FastAPI) -> AsyncIterator[None]: metas_store = MetasStore(root_dir / "speaker_info") - setting_ui_template = Jinja2Templates( - directory=engine_root() / "ui_template", - variable_start_string="", - variable_end_string="", - ) - def get_engine(core_version: Optional[str]) -> TTSEngine: if core_version is None: return tts_engines[latest_core_version] @@ -157,11 +150,7 @@ def get_core(core_version: Optional[str]) -> CoreAdapter: app.include_router( generate_engine_info_router(get_core, cores, engine_manifest_data) ) - app.include_router( - generate_setting_router( - setting_loader, engine_manifest_data, setting_ui_template - ) - ) + app.include_router(generate_setting_router(setting_loader, engine_manifest_data)) @app.get("/", response_class=HTMLResponse, tags=["その他"]) async def get_portal() -> str: diff --git a/voicevox_engine/app/routers/setting.py b/voicevox_engine/app/routers/setting.py index f52855375..7207533de 100644 --- a/voicevox_engine/app/routers/setting.py +++ b/voicevox_engine/app/routers/setting.py @@ -8,14 +8,20 @@ from voicevox_engine.engine_manifest.EngineManifest import EngineManifest from voicevox_engine.setting.Setting import CorsPolicyMode, Setting from voicevox_engine.setting.SettingLoader import SettingHandler +from voicevox_engine.utility.path_utility import engine_root from ..dependencies import check_disabled_mutable_api +_setting_ui_template = Jinja2Templates( + directory=engine_root() / "ui_template", + variable_start_string="", + variable_end_string="", +) + def generate_setting_router( setting_loader: SettingHandler, engine_manifest_data: EngineManifest, - setting_ui_template: Jinja2Templates, ) -> APIRouter: """設定 API Router を生成する""" router = APIRouter() @@ -34,7 +40,7 @@ def setting_get(request: Request) -> Response: if allow_origin is None: allow_origin = "" - return setting_ui_template.TemplateResponse( + return _setting_ui_template.TemplateResponse( "ui.html", { "request": request,