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

Function importConfig

web/src/components/playground/configStorage.js:175–203  ·  view source on GitHub ↗
(file)

Source from the content-addressed store, hash-verified

173 * @returns {Promise<Object>} 导入的配置对象
174 */
175export const importConfig = (file) => {
176 return new Promise((resolve, reject) => {
177 try {
178 const reader = new FileReader();
179 reader.onload = (e) => {
180 try {
181 const importedConfig = JSON.parse(e.target.result);
182
183 if (importedConfig.inputs && importedConfig.parameterEnabled) {
184 // 如果导入的配置包含消息,也一起导入
185 if (importedConfig.messages && Array.isArray(importedConfig.messages)) {
186 saveMessages(importedConfig.messages);
187 }
188
189 resolve(importedConfig);
190 } else {
191 reject(new Error('配置文件格式无效'));
192 }
193 } catch (parseError) {
194 reject(new Error('解析配置文件失败: ' + parseError.message));
195 }
196 };
197 reader.onerror = () => reject(new Error('读取文件失败'));
198 reader.readAsText(file);
199 } catch (error) {
200 reject(new Error('导入配置失败: ' + error.message));
201 }
202 });
203};

Callers 1

handleFileChangeFunction · 0.90

Calls 1

saveMessagesFunction · 0.85

Tested by

no test coverage detected