Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

整理: setting_ui_template をルーターに移動 #1213

Merged
merged 3 commits into from
May 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import uvicorn
from fastapi import FastAPI, HTTPException
from fastapi.templating import Jinja2Templates

from voicevox_engine import __version__
from voicevox_engine.app.dependencies import deprecated_mutable_api
Expand Down Expand Up @@ -119,12 +118,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="<JINJA_PRE>",
variable_end_string="<JINJA_POST>",
)

# @app.on_event("startup")
# async def start_catch_disconnection():
# if cancellable_engine is not None:
Expand Down Expand Up @@ -162,11 +155,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 = configure_openapi_schema(app)

Expand Down
10 changes: 8 additions & 2 deletions voicevox_engine/app/routers/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="<JINJA_PRE>",
variable_end_string="<JINJA_POST>",
)


def generate_setting_router(
setting_loader: SettingHandler,
engine_manifest_data: EngineManifest,
setting_ui_template: Jinja2Templates,
) -> APIRouter:
"""設定 API Router を生成する"""
router = APIRouter()
Expand All @@ -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,
Expand Down