import nonebot

from pydantic import BaseModel

class Config(BaseModel):
    module_web_render_weburl: str = "localhost:5173"
    module_web_render_instance: str = ""
    module_web_render_playwright_ws: str = ""

    def get_instance_baseurl(self):
        if self.module_web_render_instance:
            return self.module_web_render_instance.removesuffix('/')
        config = nonebot.get_driver().config
        ip = str(config.host)
        if ip == "0.0.0.0":
            ip = "127.0.0.1"
        port = config.port
        return f'http://{ip}:{port}'

web_render_config = nonebot.get_plugin_config(Config)
