MCPcopy Create free account
hub / github.com/aiprodcoder/MIXAPI / updateOptions

Function updateOptions

web/src/components/settings/SystemSetting.js:137–190  ·  view source on GitHub ↗
(options)

Source from the content-addressed store, hash-verified

135 }, []);
136
137 const updateOptions = async (options) => {
138 setLoading(true);
139 try {
140 // 分离 checkbox 类型的选项和其他选项
141 const checkboxOptions = options.filter((opt) =>
142 opt.key.toLowerCase().endsWith('enabled'),
143 );
144 const otherOptions = options.filter(
145 (opt) => !opt.key.toLowerCase().endsWith('enabled'),
146 );
147
148 // 处理 checkbox 类型的选项
149 for (const opt of checkboxOptions) {
150 const res = await API.put('/api/option/', {
151 key: opt.key,
152 value: opt.value.toString(),
153 });
154 if (!res.data.success) {
155 showError(res.data.message);
156 return;
157 }
158 }
159
160 // 处理其他选项
161 if (otherOptions.length > 0) {
162 const requestQueue = otherOptions.map((opt) =>
163 API.put('/api/option/', {
164 key: opt.key,
165 value:
166 typeof opt.value === 'boolean' ? opt.value.toString() : opt.value,
167 }),
168 );
169
170 const results = await Promise.all(requestQueue);
171
172 // 检查所有请求是否成功
173 const errorResults = results.filter((res) => !res.data.success);
174 errorResults.forEach((res) => {
175 showError(res.data.message);
176 });
177 }
178
179 showSuccess(t('更新成功'));
180 // 更新本地状态
181 const newInputs = { ...inputs };
182 options.forEach((opt) => {
183 newInputs[opt.key] = opt.value;
184 });
185 setInputs(newInputs);
186 } catch (error) {
187 showError(t('更新失败'));
188 }
189 setLoading(false);
190 };
191
192 const handleFormChange = (values) => {
193 setInputs(values);

Callers 12

submitWorkerFunction · 0.85
submitServerAddressFunction · 0.85
submitSMTPFunction · 0.85
submitWeChatFunction · 0.85
submitGitHubOAuthFunction · 0.85
submitOIDCSettingsFunction · 0.85
submitTelegramSettingsFunction · 0.85
submitTurnstileFunction · 0.85
submitLinuxDOOAuthFunction · 0.85
handleCheckboxChangeFunction · 0.85

Calls 3

showErrorFunction · 0.90
showSuccessFunction · 0.90
tFunction · 0.70

Tested by

no test coverage detected