74
74
from ..utils .logger import logger
75
75
from ..common .maa_config_data import maa_config_data
76
76
from ..common .typeddict import (
77
- InterfaceData ,
78
77
TaskItem ,
79
78
Interval ,
80
79
RefreshTime ,
@@ -100,11 +99,89 @@ def __init__(self, parent=None):
100
99
self .init_widget_text ()
101
100
if cfg .get (cfg .resource_exist ):
102
101
self .init_ui ()
102
+ self .check_task_consistency ()
103
103
104
104
else :
105
105
logger .warning ("资源缺失" )
106
106
self .show_error (self .tr ("Resource file not detected" ))
107
107
108
+ def get_option_case_names (self , interface_data : dict , option_key : str ) -> list :
109
+ """
110
+ 提取interface.json中指定option键名的选项name列表
111
+
112
+ :param interface_data: 加载后的interface.json字典数据
113
+ :param option_key: 需要查询的option键名(如"选择区域"、"跳过剧情"等)
114
+ :return: 该键名对应cases中的name列表
115
+ """
116
+ # 安全获取option下的目标键值(处理键不存在的情况)
117
+ target_option = interface_data .get ("option" , {}).get (option_key , {})
118
+ # 提取cases列表(处理cases不存在或非列表的情况)
119
+ cases = target_option .get ("cases" , [])
120
+
121
+ # 遍历cases提取name(过滤非字典或无name的情况)
122
+ return [
123
+ case ["name" ] for case in cases if isinstance (case , dict ) and "name" in case
124
+ ]
125
+
126
+ def check_task_consistency (self ):
127
+ """
128
+ 检查配置任务与接口模板的一致性(任务存在性+选项匹配)
129
+ """
130
+ # 获取 interface 模板任务列表和完整数据
131
+ interface_data = maa_config_data .interface_config
132
+ config_tasks = maa_config_data .config .get ("task" , [])
133
+ option_keys = list (interface_data .get ("option" , {}).keys ())
134
+ task_keys = list (
135
+ task ["name" ] for task in interface_data .get ("task" , []) if "name" in task
136
+ )
137
+
138
+ inconsistent_tasks = [] # 存储不一致的任务名称
139
+
140
+ for cfg_task in config_tasks :
141
+ task_name = cfg_task .get ("name" , "" )
142
+ task_option = cfg_task .get ("option" , [])
143
+ if not task_name :
144
+ continue # 如果任务名称为空,跳过
145
+
146
+ # 检查任务是否存在于 interface 模板
147
+ if task_name not in task_keys :
148
+ inconsistent_tasks .append (task_name )
149
+ continue
150
+ for cfg_option in task_option :
151
+ # 检查选项是否存在于 interface 模板
152
+ if cfg_option .get ("name" , "" ) not in option_keys :
153
+ inconsistent_tasks .append (
154
+ task_name + "-" + cfg_option .get ("name" , "" )
155
+ )
156
+ continue
157
+ case_list = self .get_option_case_names (
158
+ interface_data , cfg_option .get ("name" , "" )
159
+ )
160
+ # 检查选项的 value 是否存在于 interface 模板
161
+ if cfg_option .get ("value" , "" ) not in case_list :
162
+ inconsistent_tasks .append (
163
+ task_name
164
+ + "-"
165
+ + cfg_option .get ("name" , "" )
166
+ + "-"
167
+ + cfg_option .get ("value" , "" )
168
+ )
169
+ continue
170
+
171
+ # 输出结果
172
+ if inconsistent_tasks :
173
+ error_msg = (
174
+ self .tr (
175
+ "Inconsistent items between configuration tasks and interface templates"
176
+ )
177
+ + ":\n "
178
+ + "\n " .join (inconsistent_tasks )
179
+ )
180
+ logger .warning (error_msg )
181
+ self .show_error (error_msg )
182
+ else :
183
+ logger .info ("所有配置任务与接口模板一致" )
184
+
108
185
def init_widget_text (self ):
109
186
"""
110
187
初始化文本
@@ -145,6 +222,7 @@ def resource_exist(self, status: bool):
145
222
self .enable_widgets (True )
146
223
self .clear_content ()
147
224
self .init_ui ()
225
+ self .check_task_consistency ()
148
226
149
227
else :
150
228
logger .info ("资源缺失,清空界面" )
0 commit comments