Skip to content

Commit 1813e50

Browse files
committed
fix: use Field instead of direct assignment
1 parent 4481c8b commit 1813e50

File tree

1 file changed

+51
-51
lines changed

1 file changed

+51
-51
lines changed

app/models/subscription.py

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@
1313
class TLSConfig(BaseModel):
1414
"""TLS configuration - only TLS-related fields"""
1515

16-
tls: str | None = None
16+
tls: str | None = Field(None)
1717
sni: list[str] | str = Field(default_factory=list)
18-
fingerprint: str = ""
19-
allowinsecure: bool = False
18+
fingerprint: str = Field("")
19+
allowinsecure: bool = Field(False)
2020
alpn_list: list[str] = Field(default_factory=list)
21-
ech_config_list: str | None = None
21+
ech_config_list: str | None = Field(None)
2222

2323
# Reality specific
24-
reality_public_key: str = ""
25-
reality_short_id: str = ""
24+
reality_public_key: str = Field("")
25+
reality_short_id: str = Field("")
2626
reality_short_ids: list[str] = Field(default_factory=list) # List for random selection in share.py
27-
reality_spx: str = ""
28-
mldsa65_verify: str | None = None
27+
reality_spx: str = Field("")
28+
mldsa65_verify: str | None = Field(None)
2929

3030
@computed_field
3131
@property
@@ -60,7 +60,7 @@ def ais(self) -> bool:
6060
class BaseTransportConfig(BaseModel):
6161
"""Base config for all transports - minimal shared fields"""
6262

63-
path: str = ""
63+
path: str = Field("")
6464
host: list[str] | str = Field(default_factory=list)
6565

6666
model_config = {"validate_assignment": True}
@@ -70,63 +70,63 @@ class GRPCTransportConfig(BaseTransportConfig):
7070
"""GRPC/Gun transport - only grpc-specific fields"""
7171

7272
multi_mode: bool = Field(False, serialization_alias="multiMode")
73-
idle_timeout: int | None = None
74-
health_check_timeout: int | None = None
75-
permit_without_stream: bool = False
76-
initial_windows_size: int | None = None
77-
http_headers: dict[str, str] | None = None
78-
random_user_agent: bool = False
73+
idle_timeout: int | None = Field(None)
74+
health_check_timeout: int | None = Field(None)
75+
permit_without_stream: bool = Field(False)
76+
initial_windows_size: int | None = Field(None)
77+
http_headers: dict[str, str] | None = Field(None)
78+
random_user_agent: bool = Field(False)
7979

8080

8181
class WebSocketTransportConfig(BaseTransportConfig):
8282
"""WebSocket transport - only ws-specific fields"""
8383

8484
heartbeat_period: int | None = Field(None, serialization_alias="heartbeatPeriod")
85-
http_headers: dict[str, str] | None = None
86-
random_user_agent: bool = False
85+
http_headers: dict[str, str] | None = Field(None)
86+
random_user_agent: bool = Field(False)
8787

8888

8989
class XHTTPTransportConfig(BaseTransportConfig):
9090
"""xHTTP/SplitHTTP transport - only xhttp-specific fields"""
9191

92-
mode: str = "auto"
93-
no_grpc_header: bool | None = None
92+
mode: str = Field("auto")
93+
no_grpc_header: bool | None = Field(None)
9494
sc_max_each_post_bytes: int | None = Field(None, serialization_alias="scMaxEachPostBytes")
9595
sc_min_posts_interval_ms: int | None = Field(None, serialization_alias="scMinPostsIntervalMs")
9696
x_padding_bytes: str | None = Field(None, serialization_alias="xPaddingBytes")
97-
xmux: dict[str, Any] | None = None
97+
xmux: dict[str, Any] | None = Field(None)
9898
download_settings: SubscriptionInboundData | dict | None = Field(None, serialization_alias="downloadSettings")
99-
http_headers: dict[str, str] | None = None
100-
random_user_agent: bool = False
99+
http_headers: dict[str, str] | None = Field(None)
100+
random_user_agent: bool = Field(False)
101101

102102

103103
class KCPTransportConfig(BaseTransportConfig):
104104
"""KCP transport - only kcp-specific fields"""
105105

106-
header_type: str = "none"
107-
mtu: int | None = None
108-
tti: int | None = None
109-
uplink_capacity: int | None = None
110-
downlink_capacity: int | None = None
111-
congestion: bool = False
112-
read_buffer_size: int | None = None
113-
write_buffer_size: int | None = None
106+
header_type: str = Field("none")
107+
mtu: int | None = Field(None)
108+
tti: int | None = Field(None)
109+
uplink_capacity: int | None = Field(None)
110+
downlink_capacity: int | None = Field(None)
111+
congestion: bool = Field(False)
112+
read_buffer_size: int | None = Field(None)
113+
write_buffer_size: int | None = Field(None)
114114

115115

116116
class QUICTransportConfig(BaseTransportConfig):
117117
"""QUIC transport - only quic-specific fields"""
118118

119-
header_type: str = "none"
119+
header_type: str = Field("none")
120120

121121

122122
class TCPTransportConfig(BaseTransportConfig):
123123
"""TCP/Raw/HTTP transport - only tcp-specific fields"""
124124

125-
header_type: str = "none"
126-
request: dict[str, Any] | None = None
127-
response: dict[str, Any] | None = None
128-
http_headers: dict[str, str] | None = None
129-
random_user_agent: bool = False
125+
header_type: str = Field("none")
126+
request: dict[str, Any] | None = Field(None)
127+
response: dict[str, Any] | None = Field(None)
128+
http_headers: dict[str, str] | None = Field(None)
129+
random_user_agent: bool = Field(False)
130130

131131

132132
# ========== Protocol-Specific Models (Only protocol fields) ==========
@@ -150,7 +150,7 @@ class VLESSProtocolData(BaseModel):
150150
port: int | str
151151
address: str
152152
remark: str
153-
encryption: str = "none"
153+
encryption: str = Field("none")
154154

155155
model_config = {"validate_assignment": True}
156156

@@ -174,7 +174,7 @@ class ShadowsocksProtocolData(BaseModel):
174174
port: int | str
175175
address: str
176176
remark: str
177-
is_2022: bool = False
177+
is_2022: bool = Field(False)
178178

179179
model_config = {"validate_assignment": True}
180180

@@ -208,30 +208,30 @@ class SubscriptionInboundData(BaseModel):
208208
)
209209

210210
# Mux settings
211-
mux_settings: dict[str, Any] | None = None
211+
mux_settings: dict[str, Any] | None = Field(None)
212212

213213
# Shadowsocks specific
214-
is_2022: bool = False
215-
method: str = ""
216-
password: str = ""
214+
is_2022: bool = Field(False)
215+
method: str = Field("")
216+
password: str = Field("")
217217

218218
# VLESS specific
219-
encryption: str = "none"
219+
encryption: str = Field("none")
220220

221221
# Flow (from inbound, user can override)
222-
inbound_flow: str = ""
223-
flow_enabled: bool = False # Computed once: if this inbound supports flow
222+
inbound_flow: str = Field("")
223+
flow_enabled: bool = Field(False) # Computed once: if this inbound supports flow
224224

225225
# Additional settings
226-
random_user_agent: bool = False
227-
use_sni_as_host: bool = False
226+
random_user_agent: bool = Field(False)
227+
use_sni_as_host: bool = Field(False)
228228

229229
# Fragment and noise settings
230-
fragment_settings: dict[str, Any] | None = None
231-
noise_settings: dict[str, Any] | None = None
230+
fragment_settings: dict[str, Any] | None = Field(None)
231+
noise_settings: dict[str, Any] | None = Field(None)
232232

233233
# Priority and status
234-
priority: int = 0
235-
status: list[str] | None = None
234+
priority: int = Field(0)
235+
status: list[str] | None = Field(None)
236236

237237
model_config = {"validate_assignment": True}

0 commit comments

Comments
 (0)