(file)
| 2757 | } |
| 2758 | |
| 2759 | async function handleImport(file) { |
| 2760 | if (!file) return; |
| 2761 | |
| 2762 | if (!file.name.toLowerCase().endsWith('.json')) { |
| 2763 | alert('目前仅支持导入 JSON 文件'); |
| 2764 | return; |
| 2765 | } |
| 2766 | |
| 2767 | try { |
| 2768 | const text = await readFileAsText(file); |
| 2769 | const data = JSON.parse(text); |
| 2770 | const connections = normalizeImportData(data); |
| 2771 | |
| 2772 | if (connections.length === 0) { |
| 2773 | alert('未找到可导入的连接数据'); |
| 2774 | return; |
| 2775 | } |
| 2776 | |
| 2777 | connections.forEach(connection => addConnection$1(connection)); |
| 2778 | |
| 2779 | if (callbacks.renderConnectionList) { |
| 2780 | callbacks.renderConnectionList(); |
| 2781 | } |
| 2782 | |
| 2783 | if (callbacks.selectConnection) { |
| 2784 | callbacks.selectConnection(connections[0].id); |
| 2785 | } else if (callbacks.renderMessageList) { |
| 2786 | state.selectedConnectionId = connections[0].id; |
| 2787 | callbacks.renderMessageList({ force: true }); |
| 2788 | } |
| 2789 | |
| 2790 | alert(`导入成功:${connections.length} 个连接,${connections.reduce((sum, conn) => sum + conn.messages.length, 0)} 条消息`); |
| 2791 | } catch (error) { |
| 2792 | console.error('[Stream Panel] Import failed:', error); |
| 2793 | alert('导入失败,请确认文件是 Stream Panel 导出的 JSON 数据'); |
| 2794 | } |
| 2795 | } |
| 2796 | |
| 2797 | function readFileAsText(file) { |
| 2798 | return new Promise((resolve, reject) => { |
nothing calls this directly
no test coverage detected