Skip to content

Commit b8c7343

Browse files
Revert "可选后端,实现前后端分离" (#5536)
1 parent 3141ed5 commit b8c7343

File tree

27 files changed

+1255
-2150
lines changed

27 files changed

+1255
-2150
lines changed

.python-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.12
1+
3.12

astrbot/cli/commands/cmd_init.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,8 @@ async def initialize_astrbot(astrbot_root: Path) -> None:
3434
for name, path in paths.items():
3535
path.mkdir(parents=True, exist_ok=True)
3636
click.echo(f"{'Created' if not path.exists() else 'Directory exists'}: {path}")
37-
if click.confirm(
38-
"是否需要集成式 WebUI?(个人电脑推荐,服务器不推荐)",
39-
default=True,
40-
):
41-
await check_dashboard(astrbot_root / "data")
42-
else:
43-
click.echo("你可以使用在线面版(v4.14.4+),填写后端地址的方式来控制。")
37+
38+
await check_dashboard(astrbot_root / "data")
4439

4540

4641
@click.command()

astrbot/cli/commands/cmd_run.py

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ async def run_astrbot(astrbot_root: Path) -> None:
1515
from astrbot.core import LogBroker, LogManager, db_helper, logger
1616
from astrbot.core.initial_loader import InitialLoader
1717

18-
if os.environ.get("DASHBOARD_ENABLE") == "True":
19-
await check_dashboard(astrbot_root / "data")
18+
await check_dashboard(astrbot_root / "data")
2019

2120
log_broker = LogBroker()
2221
LogManager.set_queue_handler(logger, log_broker)
@@ -28,17 +27,9 @@ async def run_astrbot(astrbot_root: Path) -> None:
2827

2928

3029
@click.option("--reload", "-r", is_flag=True, help="插件自动重载")
31-
@click.option(
32-
"--host", "-H", help="Astrbot Dashboard Host,默认::", required=False, type=str
33-
)
34-
@click.option(
35-
"--port", "-p", help="Astrbot Dashboard端口,默认6185", required=False, type=str
36-
)
37-
@click.option(
38-
"--backend-only", is_flag=True, default=False, help="禁用WEBUI,仅启动后端"
39-
)
30+
@click.option("--port", "-p", help="Astrbot Dashboard端口", required=False, type=str)
4031
@click.command()
41-
def run(reload: bool, host: str, port: str, backend_only: bool) -> None:
32+
def run(reload: bool, port: str) -> None:
4233
"""运行 AstrBot"""
4334
try:
4435
os.environ["ASTRBOT_CLI"] = "1"
@@ -52,11 +43,8 @@ def run(reload: bool, host: str, port: str, backend_only: bool) -> None:
5243
os.environ["ASTRBOT_ROOT"] = str(astrbot_root)
5344
sys.path.insert(0, str(astrbot_root))
5445

55-
if port is not None:
46+
if port:
5647
os.environ["DASHBOARD_PORT"] = port
57-
if host is not None:
58-
os.environ["DASHBOARD_HOST"] = host
59-
os.environ["DASHBOARD_ENABLE"] = str(not backend_only)
6048

6149
if reload:
6250
click.echo("启用插件自动重载")

astrbot/core/config/default.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@
195195
"username": "astrbot",
196196
"password": "77b90590a8945a7d36c963981a307dc9",
197197
"jwt_secret": "",
198-
"host": "::",
198+
"host": "0.0.0.0",
199199
"port": 6185,
200200
"disable_access_log": True,
201201
"ssl": {

astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ async def _convert_handle_message_event(
419419
def run(self) -> Awaitable[Any]:
420420
if not self.host or not self.port:
421421
logger.warning(
422-
"aiocqhttp: 未配置 ws_reverse_host 或 ws_reverse_port,将使用默认值:http://[::]:6199",
422+
"aiocqhttp: 未配置 ws_reverse_host 或 ws_reverse_port,将使用默认值:http://0.0.0.0:6199",
423423
)
424424
self.host = "0.0.0.0"
425425
self.port = 6199

astrbot/core/platform/sources/qqofficial_webhook/qo_webhook_server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def __init__(
2121
self.secret = config["secret"]
2222
self.port = config.get("port", 6196)
2323
self.is_sandbox = config.get("is_sandbox", False)
24-
self.callback_server_host = config.get("callback_server_host", "::")
24+
self.callback_server_host = config.get("callback_server_host", "0.0.0.0")
2525

2626
if isinstance(self.port, str):
2727
self.port = int(self.port)

astrbot/core/platform/sources/wecom/wecom_adapter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class WecomServer:
4343
def __init__(self, event_queue: asyncio.Queue, config: dict) -> None:
4444
self.server = quart.Quart(__name__)
4545
self.port = int(cast(str, config.get("port")))
46-
self.callback_server_host = config.get("callback_server_host", "::")
46+
self.callback_server_host = config.get("callback_server_host", "0.0.0.0")
4747
self.server.add_url_rule(
4848
"/callback/command",
4949
view_func=self.verify,
@@ -407,7 +407,7 @@ async def convert_wechat_kf_message(self, msg: dict) -> AstrBotMessage | None:
407407
abm.message = [Image(file=path, url=path)]
408408
elif msgtype == "voice":
409409
media_id = msg.get("voice", {}).get("media_id", "")
410-
resp = await asyncio.get_event_loop().run_in_executor(
410+
resp: Response = await asyncio.get_event_loop().run_in_executor(
411411
None,
412412
self.client.media.download,
413413
media_id,

astrbot/core/utils/io.py

Lines changed: 5 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import asyncio
21
import base64
32
import logging
43
import os
@@ -8,7 +7,6 @@
87
import time
98
import uuid
109
import zipfile
11-
from ipaddress import IPv4Address, IPv6Address, ip_address
1210
from pathlib import Path
1311

1412
import aiohttp
@@ -208,53 +206,18 @@ def file_to_base64(file_path: str) -> str:
208206
return "base64://" + base64_str
209207

210208

211-
def get_local_ip_addresses() -> list[IPv4Address | IPv6Address]:
209+
def get_local_ip_addresses():
212210
net_interfaces = psutil.net_if_addrs()
213-
network_ips: list[IPv4Address | IPv6Address] = []
211+
network_ips = []
214212

215-
for _, addrs in net_interfaces.items():
213+
for interface, addrs in net_interfaces.items():
216214
for addr in addrs:
217-
if addr.family == socket.AF_INET:
218-
network_ips.append(ip_address(addr.address))
219-
elif addr.family == socket.AF_INET6:
220-
# 过滤掉 IPv6 的 link-local 地址(fe80:...)
221-
ip = ip_address(addr.address.split("%")[0]) # 处理带 zone index 的情况
222-
if not ip.is_link_local:
223-
network_ips.append(ip)
215+
if addr.family == socket.AF_INET: # 使用 socket.AF_INET 代替 psutil.AF_INET
216+
network_ips.append(addr.address)
224217

225218
return network_ips
226219

227220

228-
async def get_public_ip_address() -> list[IPv4Address | IPv6Address]:
229-
urls = [
230-
"https://api64.ipify.org",
231-
"https://ident.me",
232-
"https://ifconfig.me",
233-
"https://icanhazip.com",
234-
]
235-
found_ips: dict[int, IPv4Address | IPv6Address] = {}
236-
237-
async def fetch(session: aiohttp.ClientSession, url: str):
238-
try:
239-
async with session.get(url, timeout=3) as resp:
240-
if resp.status == 200:
241-
raw_ip = (await resp.text()).strip()
242-
ip = ip_address(raw_ip)
243-
if ip.version not in found_ips:
244-
found_ips[ip.version] = ip
245-
except Exception as e:
246-
# Ignore errors from individual services so that a single failing
247-
# endpoint does not prevent discovering the public IP from others.
248-
logger.debug("Failed to fetch public IP from %s: %s", url, e)
249-
250-
async with aiohttp.ClientSession() as session:
251-
tasks = [fetch(session, url) for url in urls]
252-
await asyncio.gather(*tasks)
253-
254-
# 返回找到的所有 IP 对象列表
255-
return list(found_ips.values())
256-
257-
258221
async def get_dashboard_version():
259222
dist_dir = os.path.join(get_astrbot_data_path(), "dist")
260223
if os.path.exists(dist_dir):

astrbot/dashboard/routes/__init__.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,16 @@
99
from .cron import CronRoute
1010
from .file import FileRoute
1111
from .knowledge_base import KnowledgeBaseRoute
12-
from .live_chat import LiveChatRoute
1312
from .log import LogRoute
1413
from .open_api import OpenApiRoute
1514
from .persona import PersonaRoute
1615
from .platform import PlatformRoute
1716
from .plugin import PluginRoute
18-
from .response import Response
19-
from .route import RouteContext
2017
from .session_management import SessionManagementRoute
2118
from .skills import SkillsRoute
2219
from .stat import StatRoute
2320
from .static_file import StaticFileRoute
2421
from .subagent import SubAgentRoute
25-
from .t2i import T2iRoute
2622
from .tools import ToolsRoute
2723
from .update import UpdateRoute
2824

@@ -50,8 +46,4 @@
5046
"ToolsRoute",
5147
"SkillsRoute",
5248
"UpdateRoute",
53-
"T2iRoute",
54-
"LiveChatRoute",
55-
"Response",
56-
"RouteContext",
5749
]

astrbot/dashboard/routes/route.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from dataclasses import asdict, dataclass
1+
from dataclasses import dataclass
22

33
from quart import Quart
44

@@ -57,7 +57,3 @@ def ok(self, data: dict | list | None = None, message: str | None = None):
5757
self.data = data
5858
self.message = message
5959
return self
60-
61-
def to_json(self):
62-
# Return a plain dict so callers can safely wrap with jsonify()
63-
return asdict(self)

0 commit comments

Comments
 (0)