File size: 1,137 Bytes
0a1b571
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from typing import Protocol, cast

from hibiapi.app.routes import (
    bika,
    bilibili,
    netease,
    pixiv,
    qrcode,
    sauce,
    tieba,
    wallpaper,
)
from hibiapi.utils.config import APIConfig
from hibiapi.utils.exceptions import ExceptionReturn
from hibiapi.utils.log import logger
from hibiapi.utils.routing import SlashRouter

router = SlashRouter(
    responses={
        code: {
            "model": ExceptionReturn,
        }
        for code in (400, 422, 500, 502)
    }
)


class RouteInterface(Protocol):
    router: SlashRouter
    __mount__: str
    __config__: APIConfig


modules = cast(
    list[RouteInterface],
    [bilibili, netease, pixiv, qrcode, sauce, tieba, wallpaper, bika],
)

for module in modules:
    mount = (
        mount_point
        if (mount_point := module.__mount__).startswith("/")
        else f"/{mount_point}"
    )

    if not module.__config__["enabled"].as_bool():
        logger.warning(
            f"API Route <y><b>{mount}</b></y> has been "
            "<r><b>disabled</b></r> in config."
        )
        continue
    router.include_router(module.router, prefix=mount)