File size: 2,166 Bytes
6bff6a1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from pathlib import Path

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

from app.core.auth import is_function_enabled

router = APIRouter()
STATIC_DIR = Path(__file__).resolve().parents[3] / "_public" / "static"


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


@router.get("/", include_in_schema=False)
async def root():
    if is_function_enabled():
        return RedirectResponse(url="/login")
    return RedirectResponse(url="/admin/login")


@router.get("/login", include_in_schema=False)
async def function_login():
    if not is_function_enabled():
        raise HTTPException(status_code=404, detail="Not Found")
    return _function_page_response("function/pages/login.html")


@router.get("/imagine", include_in_schema=False)
async def function_imagine():
    if not is_function_enabled():
        raise HTTPException(status_code=404, detail="Not Found")
    return _function_page_response("function/pages/imagine.html")


@router.get("/imagine-lab", include_in_schema=False)
async def function_imagine_lab():
    if not is_function_enabled():
        raise HTTPException(status_code=404, detail="Not Found")
    return _function_page_response("function/pages/imagine-lab.html")


@router.get("/voice", include_in_schema=False)
async def function_voice():
    if not is_function_enabled():
        raise HTTPException(status_code=404, detail="Not Found")
    return _function_page_response("function/pages/voice.html")


@router.get("/video", include_in_schema=False)
async def function_video():
    if not is_function_enabled():
        raise HTTPException(status_code=404, detail="Not Found")
    return _function_page_response("function/pages/video.html")


@router.get("/chat", include_in_schema=False)
async def function_chat():
    if not is_function_enabled():
        raise HTTPException(status_code=404, detail="Not Found")
    return _function_page_response("function/pages/chat.html")