MCPcopy Create free account
hub / github.com/bywwcnll/StreamPanel / handleImport

Function handleImport

devtools/modules/importManager.js:15–51  ·  view source on GitHub ↗
(file)

Source from the content-addressed store, hash-verified

13}
14
15export async function handleImport(file) {
16 if (!file) return;
17
18 if (!file.name.toLowerCase().endsWith('.json')) {
19 alert('目前仅支持导入 JSON 文件');
20 return;
21 }
22
23 try {
24 const text = await readFileAsText(file);
25 const data = JSON.parse(text);
26 const connections = normalizeImportData(data);
27
28 if (connections.length === 0) {
29 alert('未找到可导入的连接数据');
30 return;
31 }
32
33 connections.forEach(connection => addConnection(connection));
34
35 if (callbacks.renderConnectionList) {
36 callbacks.renderConnectionList();
37 }
38
39 if (callbacks.selectConnection) {
40 callbacks.selectConnection(connections[0].id);
41 } else if (callbacks.renderMessageList) {
42 state.selectedConnectionId = connections[0].id;
43 callbacks.renderMessageList({ force: true });
44 }
45
46 alert(`导入成功:${connections.length} 个连接,${connections.reduce((sum, conn) => sum + conn.messages.length, 0)} 条消息`);
47 } catch (error) {
48 console.error('[Stream Panel] Import failed:', error);
49 alert('导入失败,请确认文件是 Stream Panel 导出的 JSON 数据');
50 }
51}
52
53function readFileAsText(file) {
54 return new Promise((resolve, reject) => {

Callers

nothing calls this directly

Calls 3

addConnectionFunction · 0.90
readFileAsTextFunction · 0.70
normalizeImportDataFunction · 0.70

Tested by

no test coverage detected