66import json
77import os
88from dataclasses import dataclass
9- from typing import Dict , Literal
9+ from typing import Dict , List , Literal
1010
1111
1212@dataclass
@@ -20,6 +20,23 @@ class ProviderConfig:
2020 user_info_path : str = '/api/user/self'
2121 api_user_key : str = 'new-api-user'
2222 bypass_method : Literal ['waf_cookies' ] | None = None
23+ waf_cookie_names : List [str ] | None = None
24+
25+ def __post_init__ (self ):
26+ required_waf_cookies = set ()
27+ if self .waf_cookie_names and isinstance (self .waf_cookie_names , List ):
28+ for item in self .waf_cookie_names :
29+ name = "" if not item or not isinstance (item , str ) else item .strip ()
30+ if not name :
31+ print (f'[WARNING] Found invalid WAF cookie name: { item } ' )
32+ continue
33+
34+ required_waf_cookies .add (name )
35+
36+ if not required_waf_cookies :
37+ self .bypass_method = None
38+
39+ self .waf_cookie_names = list (required_waf_cookies )
2340
2441 @classmethod
2542 def from_dict (cls , name : str , data : dict ) -> 'ProviderConfig' :
@@ -37,6 +54,7 @@ def from_dict(cls, name: str, data: dict) -> 'ProviderConfig':
3754 user_info_path = data .get ('user_info_path' , '/api/user/self' ),
3855 api_user_key = data .get ('api_user_key' , 'new-api-user' ),
3956 bypass_method = data .get ('bypass_method' ),
57+ waf_cookie_names = data .get ('waf_cookie_names' ),
4058 )
4159
4260 def needs_waf_cookies (self ) -> bool :
@@ -66,6 +84,7 @@ def load_from_env(cls) -> 'AppConfig':
6684 user_info_path = '/api/user/self' ,
6785 api_user_key = 'new-api-user' ,
6886 bypass_method = 'waf_cookies' ,
87+ waf_cookie_names = ['acw_tc' , 'cdn_sec_tc' , 'acw_sc__v2' ],
6988 ),
7089 'agentrouter' : ProviderConfig (
7190 name = 'agentrouter' ,
@@ -74,7 +93,8 @@ def load_from_env(cls) -> 'AppConfig':
7493 sign_in_path = None , # 无需签到接口,查询用户信息时自动完成签到
7594 user_info_path = '/api/user/self' ,
7695 api_user_key = 'new-api-user' ,
77- bypass_method = None ,
96+ bypass_method = 'waf_cookies' ,
97+ waf_cookie_names = ['acw_tc' ],
7898 ),
7999 }
80100
0 commit comments