@@ -2,10 +2,9 @@ import { Button } from '@heroui/button';
22import { useDisclosure } from '@heroui/modal' ;
33import { Tab , Tabs } from '@heroui/tabs' ;
44import clsx from 'clsx' ;
5- import { useEffect , useMemo , useRef , useState } from 'react' ;
5+ import { useEffect , useMemo , useState } from 'react' ;
66import toast from 'react-hot-toast' ;
77import { IoMdRefresh } from 'react-icons/io' ;
8- import { FiDownload , FiUpload } from 'react-icons/fi' ;
98
109import AddButton from '@/components/button/add_button' ;
1110import HTTPClientDisplayCard from '@/components/display_card/http_client' ;
@@ -56,9 +55,7 @@ export default function NetworkPage () {
5655 deleteNetworkConfig,
5756 enableNetworkConfig,
5857 enableDebugNetworkConfig,
59- updateSingleConfig,
6058 } = useConfig ( ) ;
61- const fileInputRef = useRef < HTMLInputElement > ( null ) ;
6259 const [ activeField , setActiveField ] =
6360 useState < keyof OneBotConfig [ 'network' ] > ( 'httpServers' ) ;
6461 const [ activeName , setActiveName ] = useState < string > ( '' ) ;
@@ -102,45 +99,6 @@ export default function NetworkPage () {
10299 onOpen ( ) ;
103100 } ;
104101
105- // 导出网络配置
106- const handleExport = ( ) => {
107- const blob = new Blob ( [ JSON . stringify ( config . network , null , 2 ) ] , { type : 'application/json' } ) ;
108- const link = document . createElement ( 'a' ) ;
109- link . href = URL . createObjectURL ( blob ) ;
110- link . download = `network-config-${ Date . now ( ) } .json` ;
111- link . click ( ) ;
112- URL . revokeObjectURL ( link . href ) ;
113- toast . success ( '导出成功' ) ;
114- } ;
115-
116- // 导入网络配置
117- const handleFileChange = async ( e : React . ChangeEvent < HTMLInputElement > ) => {
118- const file = e . target . files ?. [ 0 ] ;
119- if ( ! file ) return ;
120- e . target . value = '' ;
121-
122- try {
123- const data = JSON . parse ( await file . text ( ) ) as OneBotConfig [ 'network' ] ;
124- const keys : ( keyof OneBotConfig [ 'network' ] ) [ ] = [ 'httpServers' , 'httpClients' , 'httpSseServers' , 'websocketServers' , 'websocketClients' ] ;
125- if ( keys . some ( k => ! Array . isArray ( data [ k ] ) ) ) throw new Error ( '配置格式错误' ) ;
126-
127- dialog . confirm ( {
128- title : '导入配置' ,
129- content : '确定导入?这将覆盖现有网络配置。' ,
130- onConfirm : async ( ) => {
131- try {
132- await updateSingleConfig ( 'network' , data ) ;
133- toast . success ( '导入成功' ) ;
134- } catch ( err ) {
135- toast . error ( `导入失败: ${ ( err as Error ) . message } ` ) ;
136- }
137- } ,
138- } ) ;
139- } catch ( err ) {
140- toast . error ( `解析失败: ${ ( err as Error ) . message } ` ) ;
141- }
142- } ;
143-
144102 const onDelete = async (
145103 field : keyof OneBotConfig [ 'network' ] ,
146104 name : string
@@ -415,21 +373,6 @@ export default function NetworkPage () {
415373 < PageLoading loading = { loading } />
416374 < div className = 'flex mb-6 items-center gap-4' >
417375 < AddButton onOpen = { handleClickCreate } />
418- < Button
419- className = "bg-default-100/50 hover:bg-default-200/50 text-default-700 backdrop-blur-md"
420- startContent = { < FiUpload size = { 18 } /> }
421- onPress = { handleExport }
422- >
423- 导出
424- </ Button >
425- < Button
426- className = "bg-default-100/50 hover:bg-default-200/50 text-default-700 backdrop-blur-md"
427- startContent = { < FiDownload size = { 18 } /> }
428- onPress = { ( ) => fileInputRef . current ?. click ( ) }
429- >
430- 导入
431- </ Button >
432- < input ref = { fileInputRef } type = "file" accept = ".json" className = "hidden" onChange = { handleFileChange } />
433376 < Button
434377 isIconOnly
435378 className = "bg-default-100/50 hover:bg-default-200/50 text-default-700 backdrop-blur-md"
0 commit comments