mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-07-19 12:03:37 +00:00
fix: sse配置缺失
This commit is contained in:
59
napcat.webui/src/components/display_card/http_sse_server.tsx
Normal file
59
napcat.webui/src/components/display_card/http_sse_server.tsx
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
import { Chip } from '@heroui/chip'
|
||||||
|
|
||||||
|
import NetworkDisplayCard from './common_card'
|
||||||
|
import type { NetworkDisplayCardFields } from './common_card'
|
||||||
|
|
||||||
|
interface HTTPSSEServerDisplayCardProps {
|
||||||
|
data: OneBotConfig['network']['httpSseServers'][0]
|
||||||
|
showType?: boolean
|
||||||
|
onEdit: () => void
|
||||||
|
onEnable: () => Promise<void>
|
||||||
|
onDelete: () => Promise<void>
|
||||||
|
onEnableDebug: () => Promise<void>
|
||||||
|
}
|
||||||
|
|
||||||
|
const HTTPSSEServerDisplayCard: React.FC<HTTPSSEServerDisplayCardProps> = (
|
||||||
|
props
|
||||||
|
) => {
|
||||||
|
const { data, showType, onEdit, onEnable, onDelete, onEnableDebug } = props
|
||||||
|
const { host, port, enableCors, enableWebsocket, messagePostFormat } = data
|
||||||
|
|
||||||
|
const fields: NetworkDisplayCardFields<'httpServers'> = [
|
||||||
|
{ label: '主机', value: host },
|
||||||
|
{ label: '端口', value: port },
|
||||||
|
{ label: '消息格式', value: messagePostFormat },
|
||||||
|
{
|
||||||
|
label: 'CORS',
|
||||||
|
value: enableCors,
|
||||||
|
render: (value) => (
|
||||||
|
<Chip color={value ? 'success' : 'default'} size="sm" variant="flat">
|
||||||
|
{value ? '已启用' : '未启用'}
|
||||||
|
</Chip>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'WS',
|
||||||
|
value: enableWebsocket,
|
||||||
|
render: (value) => (
|
||||||
|
<Chip color={value ? 'success' : 'default'} size="sm" variant="flat">
|
||||||
|
{value ? '已启用' : '未启用'}
|
||||||
|
</Chip>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
return (
|
||||||
|
<NetworkDisplayCard
|
||||||
|
data={data}
|
||||||
|
showType={showType}
|
||||||
|
typeLabel="HTTP服务器"
|
||||||
|
fields={fields}
|
||||||
|
onEdit={onEdit}
|
||||||
|
onEnable={onEnable}
|
||||||
|
onDelete={onDelete}
|
||||||
|
onEnableDebug={onEnableDebug}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default HTTPSSEServerDisplayCard
|
120
napcat.webui/src/components/network_edit/http_sse.tsx
Normal file
120
napcat.webui/src/components/network_edit/http_sse.tsx
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
import GenericForm from './generic_form'
|
||||||
|
import type { Field } from './generic_form'
|
||||||
|
|
||||||
|
export interface HTTPServerSSEFormProps {
|
||||||
|
data?: OneBotConfig['network']['httpSseServers'][0]
|
||||||
|
onClose: () => void
|
||||||
|
onSubmit: (
|
||||||
|
data: OneBotConfig['network']['httpSseServers'][0]
|
||||||
|
) => Promise<void>
|
||||||
|
}
|
||||||
|
|
||||||
|
type HTTPServerSSEFormType = OneBotConfig['network']['httpSseServers']
|
||||||
|
|
||||||
|
const HTTPServerSSEForm: React.FC<HTTPServerSSEFormProps> = ({
|
||||||
|
data,
|
||||||
|
onClose,
|
||||||
|
onSubmit
|
||||||
|
}) => {
|
||||||
|
const defaultValues: HTTPServerSSEFormType[0] = {
|
||||||
|
enable: false,
|
||||||
|
name: '',
|
||||||
|
host: '0.0.0.0',
|
||||||
|
port: 3000,
|
||||||
|
enableCors: true,
|
||||||
|
enableWebsocket: true,
|
||||||
|
messagePostFormat: 'array',
|
||||||
|
token: '',
|
||||||
|
debug: false,
|
||||||
|
reportSelfMessage: false
|
||||||
|
}
|
||||||
|
|
||||||
|
const fields: Field<'httpSseServers'>[] = [
|
||||||
|
{
|
||||||
|
name: 'enable',
|
||||||
|
label: '启用',
|
||||||
|
type: 'switch',
|
||||||
|
description: '保存后启用此配置',
|
||||||
|
colSpan: 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'debug',
|
||||||
|
label: '开启Debug',
|
||||||
|
type: 'switch',
|
||||||
|
description: '是否开启调试模式',
|
||||||
|
colSpan: 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'name',
|
||||||
|
label: '名称',
|
||||||
|
type: 'input',
|
||||||
|
placeholder: '请输入名称',
|
||||||
|
isRequired: true,
|
||||||
|
isDisabled: !!data
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'host',
|
||||||
|
label: 'Host',
|
||||||
|
type: 'input',
|
||||||
|
placeholder: '请输入主机地址',
|
||||||
|
isRequired: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'port',
|
||||||
|
label: 'Port',
|
||||||
|
type: 'input',
|
||||||
|
placeholder: '请输入端口',
|
||||||
|
isRequired: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'enableCors',
|
||||||
|
label: '启用CORS',
|
||||||
|
type: 'switch',
|
||||||
|
description: '是否启用CORS跨域',
|
||||||
|
colSpan: 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'enableWebsocket',
|
||||||
|
label: '启用Websocket',
|
||||||
|
type: 'switch',
|
||||||
|
description: '是否启用Websocket',
|
||||||
|
colSpan: 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'messagePostFormat',
|
||||||
|
label: '消息格式',
|
||||||
|
type: 'select',
|
||||||
|
placeholder: '请选择消息格式',
|
||||||
|
isRequired: true,
|
||||||
|
options: [
|
||||||
|
{ key: 'array', value: 'Array' },
|
||||||
|
{ key: 'string', value: 'String' }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'token',
|
||||||
|
label: 'Token',
|
||||||
|
type: 'input',
|
||||||
|
placeholder: '请输入Token'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'reportSelfMessage',
|
||||||
|
label: '上报自身消息',
|
||||||
|
type: 'switch',
|
||||||
|
description: '是否上报自身消息',
|
||||||
|
colSpan: 1
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
return (
|
||||||
|
<GenericForm
|
||||||
|
data={data}
|
||||||
|
defaultValues={defaultValues}
|
||||||
|
onClose={onClose}
|
||||||
|
onSubmit={onSubmit}
|
||||||
|
fields={fields}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default HTTPServerSSEForm
|
@@ -5,12 +5,14 @@ import useConfig from '@/hooks/use-config'
|
|||||||
|
|
||||||
import HTTPClientForm from './http_client'
|
import HTTPClientForm from './http_client'
|
||||||
import HTTPServerForm from './http_server'
|
import HTTPServerForm from './http_server'
|
||||||
|
import HTTPServerSSEForm from './http_sse'
|
||||||
import WebsocketClientForm from './ws_client'
|
import WebsocketClientForm from './ws_client'
|
||||||
import WebsocketServerForm from './ws_server'
|
import WebsocketServerForm from './ws_server'
|
||||||
|
|
||||||
const modalTitle = {
|
const modalTitle = {
|
||||||
httpServers: 'HTTP Server',
|
httpServers: 'HTTP Server',
|
||||||
httpClients: 'HTTP Client',
|
httpClients: 'HTTP Client',
|
||||||
|
httpSseServers: 'HTTP SSE Server',
|
||||||
websocketServers: 'Websocket Server',
|
websocketServers: 'Websocket Server',
|
||||||
websocketClients: 'Websocket Client'
|
websocketClients: 'Websocket Client'
|
||||||
}
|
}
|
||||||
@@ -82,6 +84,14 @@ const NetworkFormModal = <T extends keyof OneBotConfig['network']>(
|
|||||||
onSubmit={onSubmit}
|
onSubmit={onSubmit}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
|
case 'httpSseServers':
|
||||||
|
return (
|
||||||
|
<HTTPServerSSEForm
|
||||||
|
data={data as OneBotConfig['network']['httpSseServers'][0]}
|
||||||
|
onClose={onClose}
|
||||||
|
onSubmit={onSubmit}
|
||||||
|
/>
|
||||||
|
)
|
||||||
default:
|
default:
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
@@ -9,6 +9,7 @@ import { IoMdRefresh } from 'react-icons/io'
|
|||||||
import AddButton from '@/components/button/add_button'
|
import AddButton from '@/components/button/add_button'
|
||||||
import HTTPClientDisplayCard from '@/components/display_card/http_client'
|
import HTTPClientDisplayCard from '@/components/display_card/http_client'
|
||||||
import HTTPServerDisplayCard from '@/components/display_card/http_server'
|
import HTTPServerDisplayCard from '@/components/display_card/http_server'
|
||||||
|
import HTTPSSEServerDisplayCard from '@/components/display_card/http_sse_server'
|
||||||
import WebsocketClientDisplayCard from '@/components/display_card/ws_client'
|
import WebsocketClientDisplayCard from '@/components/display_card/ws_client'
|
||||||
import WebsocketServerDisplayCard from '@/components/display_card/ws_server'
|
import WebsocketServerDisplayCard from '@/components/display_card/ws_server'
|
||||||
import NetworkFormModal from '@/components/network_edit/modal'
|
import NetworkFormModal from '@/components/network_edit/modal'
|
||||||
@@ -59,7 +60,13 @@ export default function NetworkPage() {
|
|||||||
useState<keyof OneBotConfig['network']>('httpServers')
|
useState<keyof OneBotConfig['network']>('httpServers')
|
||||||
const [activeName, setActiveName] = useState<string>('')
|
const [activeName, setActiveName] = useState<string>('')
|
||||||
const {
|
const {
|
||||||
network: { httpServers, httpClients, websocketServers, websocketClients }
|
network: {
|
||||||
|
httpServers,
|
||||||
|
httpClients,
|
||||||
|
httpSseServers,
|
||||||
|
websocketServers,
|
||||||
|
websocketClients
|
||||||
|
}
|
||||||
} = config
|
} = config
|
||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
const { isOpen, onOpen, onOpenChange } = useDisclosure()
|
const { isOpen, onOpen, onOpenChange } = useDisclosure()
|
||||||
@@ -204,6 +211,26 @@ export default function NetworkPage() {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
|
case 'httpSseServers':
|
||||||
|
return (
|
||||||
|
<HTTPSSEServerDisplayCard
|
||||||
|
key={item.name}
|
||||||
|
showType={showType}
|
||||||
|
data={item as OneBotConfig['network']['httpSseServers'][0]}
|
||||||
|
onDelete={async () => {
|
||||||
|
await onDelete('httpSseServers', item.name)
|
||||||
|
}}
|
||||||
|
onEdit={() => {
|
||||||
|
onEdit('httpSseServers', item.name)
|
||||||
|
}}
|
||||||
|
onEnable={async () => {
|
||||||
|
await onEnable('httpSseServers', item.name)
|
||||||
|
}}
|
||||||
|
onEnableDebug={async () => {
|
||||||
|
await onEnableDebug('httpSseServers', item.name)
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)
|
||||||
case 'websocketServers':
|
case 'websocketServers':
|
||||||
return (
|
return (
|
||||||
<WebsocketServerDisplayCard
|
<WebsocketServerDisplayCard
|
||||||
@@ -255,7 +282,8 @@ export default function NetworkPage() {
|
|||||||
...httpServers,
|
...httpServers,
|
||||||
...httpClients,
|
...httpClients,
|
||||||
...websocketServers,
|
...websocketServers,
|
||||||
...websocketClients
|
...websocketClients,
|
||||||
|
...httpSseServers
|
||||||
]
|
]
|
||||||
.sort((a, b) => a.name.localeCompare(b.name))
|
.sort((a, b) => a.name.localeCompare(b.name))
|
||||||
.map((item) => {
|
.map((item) => {
|
||||||
@@ -300,6 +328,11 @@ export default function NetworkPage() {
|
|||||||
title: 'HTTP客户端',
|
title: 'HTTP客户端',
|
||||||
items: httpClients.map((item) => renderCard('httpClients', item))
|
items: httpClients.map((item) => renderCard('httpClients', item))
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
key: 'httpSseServers',
|
||||||
|
title: 'HTTP SSE服务器',
|
||||||
|
items: httpSseServers.map((item) => renderCard('httpSseServers', item))
|
||||||
|
},
|
||||||
{
|
{
|
||||||
key: 'websocketServers',
|
key: 'websocketServers',
|
||||||
title: 'Websocket服务器',
|
title: 'Websocket服务器',
|
||||||
|
@@ -11,6 +11,7 @@ const initialState: ConfigState = {
|
|||||||
network: {
|
network: {
|
||||||
httpServers: [],
|
httpServers: [],
|
||||||
httpClients: [],
|
httpClients: [],
|
||||||
|
httpSseServers: [],
|
||||||
websocketServers: [],
|
websocketServers: [],
|
||||||
websocketClients: []
|
websocketClients: []
|
||||||
},
|
},
|
||||||
|
5
napcat.webui/src/types/onebot_conf.d.ts
vendored
5
napcat.webui/src/types/onebot_conf.d.ts
vendored
@@ -44,9 +44,14 @@ interface WebsocketClientConfig extends AdapterConfig {
|
|||||||
heartInterval: number
|
heartInterval: number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface HttpSseServerConfig extends HttpServerConfig {
|
||||||
|
reportSelfMessage: boolean
|
||||||
|
}
|
||||||
|
|
||||||
interface NetworkConfig {
|
interface NetworkConfig {
|
||||||
httpServers: Array<HttpServerConfig>
|
httpServers: Array<HttpServerConfig>
|
||||||
httpClients: Array<HttpClientConfig>
|
httpClients: Array<HttpClientConfig>
|
||||||
|
httpSseServers: Array<HttpSseServerConfig>
|
||||||
websocketServers: Array<WebsocketServerConfig>
|
websocketServers: Array<WebsocketServerConfig>
|
||||||
websocketClients: Array<WebsocketClientConfig>
|
websocketClients: Array<WebsocketClientConfig>
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user