Skip to content

Commit 2039bc2

Browse files
committed
fix: pydantic model
1 parent 54460ba commit 2039bc2

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

app/core/hosts.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from app.models.host import MuxSettings, TransportSettings, BaseHost
1313

1414

15-
def _prepare_host_data(host: ProxyHost) -> dict:
15+
def _prepare_host_data(host: BaseHost) -> dict:
1616
return {
1717
"remark": host.remark,
1818
"inbound_tag": host.inbound_tag,
@@ -30,12 +30,8 @@ def _prepare_host_data(host: ProxyHost) -> dict:
3030
"random_user_agent": host.random_user_agent,
3131
"use_sni_as_host": host.use_sni_as_host,
3232
"http_headers": host.http_headers,
33-
"mux_settings": MuxSettings.model_validate(host.mux_settings).model_dump(by_alias=True, exclude_none=True)
34-
if host.mux_settings
35-
else {},
36-
"transport_settings": TransportSettings.model_validate(host.transport_settings).model_dump(
37-
by_alias=True, exclude_none=True
38-
)
33+
"mux_settings": host.mux_settings.model_dump(by_alias=True, exclude_none=True) if host.mux_settings else {},
34+
"transport_settings": host.transport_settings.model_dump(by_alias=True, exclude_none=True)
3935
if host.transport_settings
4036
else {},
4137
"status": host.status,
@@ -56,15 +52,17 @@ async def _reset_cache(self):
5652
await self.get_hosts.cache.clear()
5753

5854
@staticmethod
59-
async def _prepare_host_entry(db: AsyncSession, host: BaseHost, inbounds_list: list[str]) -> tuple[int, dict] | None:
55+
async def _prepare_host_entry(
56+
db: AsyncSession, host: BaseHost, inbounds_list: list[str]
57+
) -> tuple[int, dict] | None:
6058
if host.is_disabled or (host.inbound_tag not in inbounds_list):
6159
return None
6260

6361
downstream = None
6462
if (
6563
host.transport_settings
66-
and host.transport_settings.get("xhttp_settings")
67-
and (ds_host := host.transport_settings.get("xhttp_settings", {}).get("download_settings"))
64+
and host.transport_settings.xhttp_settings
65+
and (ds_host := host.transport_settings.xhttp_settings.download_settings)
6866
):
6967
downstream = await get_host_by_id(db, ds_host)
7068

@@ -115,6 +113,7 @@ async def get_hosts(self) -> dict[int, dict]:
115113

116114
host_manager: HostManager = HostManager()
117115

116+
118117
@on_startup
119118
async def initialize_hosts():
120119
async with GetDB() as db:

0 commit comments

Comments
 (0)