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

追加: GET / API にポータルページを配置 #1169

Merged
merged 8 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
25 changes: 24 additions & 1 deletion run.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from fastapi import Query, Request, Response
from fastapi.middleware.cors import CORSMiddleware
from fastapi.openapi.utils import get_openapi
from fastapi.responses import JSONResponse
from fastapi.responses import HTMLResponse, JSONResponse
from fastapi.templating import Jinja2Templates
from pydantic import ValidationError, parse_obj_as
from starlette.background import BackgroundTask
Expand Down Expand Up @@ -1354,6 +1354,29 @@ def setting_post(

return Response(status_code=204)

@app.get("/", response_class=HTMLResponse)
tarepan marked this conversation as resolved.
Show resolved Hide resolved
async def get_portal() -> str:
"""ポータルページを返します。"""
code_licence_url = "https://github.com/VOICEVOX/voicevox_engine?tab=readme-ov-file#%E3%83%A9%E3%82%A4%E3%82%BB%E3%83%B3%E3%82%B9-1" # noqa B950
software_licence_url = "https://github.com/VOICEVOX/voicevox_resource/tree/main/engine" # noqa B950
tarepan marked this conversation as resolved.
Show resolved Hide resolved
return f"""
<html>
<head>
<title>VOICEVOX ENGINE</title>
tarepan marked this conversation as resolved.
Show resolved Hide resolved
</head>
<body>
<h1>VOICEVOX ENGINE</h1>
VOICEVOX ENGINE へようこそ!
<ul>
<li><a href='/setting'>設定</a></li>
<li><a href='/docs'>API ドキュメント & API 呼び出し</a></li>
Hiroshiba marked this conversation as resolved.
Show resolved Hide resolved
<li>ライセンス
<ul>
<li><a href='{code_licence_url}'>コード</a></li>
tarepan marked this conversation as resolved.
Show resolved Hide resolved
<li><a href='{software_licence_url}'>製品版ソフトウェア</a></li>
</ul></li></ul></body></html>
"""

# BaseLibraryInfo/VvlibManifestモデルはAPIとして表には出ないが、エディタ側で利用したいので、手動で追加する
# ref: https://fastapi.tiangolo.com/advanced/extending-openapi/#modify-the-openapi-schema
def custom_openapi() -> Any:
Expand Down

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

22 changes: 22 additions & 0 deletions test/e2e/single_api/__snapshots__/test_get_root.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# serializer version: 1
# name: test_get_root_200
'''

<html>
<head>
<title>VOICEVOX ENGINE</title>
</head>
<body>
<h1>VOICEVOX ENGINE</h1>
VOICEVOX ENGINE へようこそ!
<ul>
<li><a href='/setting'>設定</a></li>
<li><a href='/docs'>API ドキュメント & API 呼び出し</a></li>
<li>ライセンス
<ul>
<li><a href='https://github.com/VOICEVOX/voicevox_engine?tab=readme-ov-file#%E3%83%A9%E3%82%A4%E3%82%BB%E3%83%B3%E3%82%B9-1'>コード</a></li>
<li><a href='https://github.com/VOICEVOX/voicevox_resource/tree/main/engine'>製品版ソフトウェア</a></li>
</ul></li></ul></body></html>

'''
# ---
12 changes: 12 additions & 0 deletions test/e2e/single_api/test_get_root.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""
/ API のテスト
"""

from fastapi.testclient import TestClient
from syrupy.assertion import SnapshotAssertion


def test_get_root_200(client: TestClient, snapshot: SnapshotAssertion) -> None:
response = client.get("/")
assert response.status_code == 200
assert snapshot == response.content.decode("utf-8")
Loading