File size: 1,290 Bytes
ddebc3e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""Static page routes for the statics-based WebUI."""

from pathlib import Path

from fastapi import APIRouter, HTTPException
from fastapi.responses import FileResponse

from app.platform.auth.middleware import is_webui_enabled
from ..static_html import serve_static_html

router = APIRouter(include_in_schema=False)

STATIC_DIR = Path(__file__).resolve().parents[3] / "statics" / "webui"


def _serve(filename: str) -> FileResponse:
    path = STATIC_DIR / filename
    if not path.exists():
        raise HTTPException(status_code=404, detail="Page not found")
    return FileResponse(path)


def _serve_html(filename: str):
    return serve_static_html(STATIC_DIR / filename)


@router.get("/webui/chat")
async def webui_chat_page():
    if not is_webui_enabled():
        raise HTTPException(status_code=404, detail="Not Found")
    return _serve_html("chat.html")


@router.get("/webui/chatkit")
async def webui_chatkit_page():
    if not is_webui_enabled():
        raise HTTPException(status_code=404, detail="Not Found")
    return _serve_html("chatkit.html")


@router.get("/webui/masonry")
async def webui_masonry_page():
    if not is_webui_enabled():
        raise HTTPException(status_code=404, detail="Not Found")
    return _serve_html("masonry.html")


__all__ = ["router"]