Skip to content

Commit

Permalink
整理: ポータル機能を router へ分離 (#1221)
Browse files Browse the repository at this point in the history
* refactor: ポータル機能を router へ分離

* refactor: single API テストを分離

* fix: リファクタリングの混入を削除

* fix: `portal` → `portal_page` にリネーム
  • Loading branch information
tarepan authored May 17, 2024
1 parent 57fdf1e commit 81a0a2f
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 22 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
22 changes: 2 additions & 20 deletions voicevox_engine/app/application.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from pathlib import Path

from fastapi import FastAPI, HTTPException
from fastapi.responses import HTMLResponse

from voicevox_engine import __version__
from voicevox_engine.app.dependencies import deprecated_mutable_api
Expand All @@ -10,6 +9,7 @@
from voicevox_engine.app.routers.engine_info import generate_engine_info_router
from voicevox_engine.app.routers.library import generate_library_router
from voicevox_engine.app.routers.morphing import generate_morphing_router
from voicevox_engine.app.routers.portal_page import generate_portal_page_router
from voicevox_engine.app.routers.preset import generate_preset_router
from voicevox_engine.app.routers.setting import generate_setting_router
from voicevox_engine.app.routers.speaker import generate_speaker_router
Expand Down Expand Up @@ -101,25 +101,7 @@ def get_core(core_version: str | None) -> CoreAdapter:
generate_engine_info_router(get_core, cores, engine_manifest_data)
)
app.include_router(generate_setting_router(setting_loader, engine_manifest_data))

@app.get("/", response_class=HTMLResponse, tags=["その他"])
async def get_portal() -> str:
"""ポータルページを返します。"""
engine_name = engine_manifest_data.name

return f"""
<html>
<head>
<title>{engine_name}</title>
</head>
<body>
<h1>{engine_name}</h1>
{engine_name} へようこそ!
<ul>
<li><a href='/setting'>設定</a></li>
<li><a href='/docs'>API ドキュメント</a></li>
</ul></body></html>
"""
app.include_router(generate_portal_page_router(engine_manifest_data))

app = configure_openapi_schema(app)

Expand Down
32 changes: 32 additions & 0 deletions voicevox_engine/app/routers/portal_page.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""ポータルページ機能を提供する API Router"""

from fastapi import APIRouter
from fastapi.responses import HTMLResponse

from voicevox_engine.engine_manifest.EngineManifest import EngineManifest


def generate_portal_page_router(engine_manifest_data: EngineManifest) -> APIRouter:
"""ポータルページ API Router を生成する"""
router = APIRouter()

@router.get("/", response_class=HTMLResponse, tags=["その他"])
async def get_portal_page() -> str:
"""ポータルページを返します。"""
engine_name = engine_manifest_data.name

return f"""
<html>
<head>
<title>{engine_name}</title>
</head>
<body>
<h1>{engine_name}</h1>
{engine_name} へようこそ!
<ul>
<li><a href='/setting'>設定</a></li>
<li><a href='/docs'>API ドキュメント</a></li>
</ul></body></html>
"""

return router

0 comments on commit 81a0a2f

Please sign in to comment.