fix: input port have range validation (#1741)
* fix port cannot be empty and have range validation * fix: do not allow user to start server with blank port config (after navigating back) * fix: thread disable button color --------- Co-authored-by: Louis <louis@jan.ai>
This commit is contained in:
parent
7401f3d798
commit
1b794b5337
@ -41,7 +41,10 @@ export default function RibbonNav() {
|
|||||||
icon: (
|
icon: (
|
||||||
<MessageCircleIcon
|
<MessageCircleIcon
|
||||||
size={20}
|
size={20}
|
||||||
className="flex-shrink-0 text-muted-foreground"
|
className={twMerge(
|
||||||
|
'flex-shrink-0 text-muted-foreground',
|
||||||
|
serverEnabled && 'text-gray-300 dark:text-gray-700'
|
||||||
|
)}
|
||||||
/>
|
/>
|
||||||
),
|
),
|
||||||
state: MainViewState.Thread,
|
state: MainViewState.Thread,
|
||||||
@ -60,7 +63,7 @@ export default function RibbonNav() {
|
|||||||
|
|
||||||
const secondaryMenus = [
|
const secondaryMenus = [
|
||||||
{
|
{
|
||||||
name: 'Local Server',
|
name: 'Local API Server',
|
||||||
icon: (
|
icon: (
|
||||||
<SquareCodeIcon
|
<SquareCodeIcon
|
||||||
size={20}
|
size={20}
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import React, { useEffect, useState } from 'react'
|
import React, { useEffect, useState } from 'react'
|
||||||
@ -55,16 +56,16 @@ const hostAtom = atom('127.0.0.1')
|
|||||||
const portAtom = atom('1337')
|
const portAtom = atom('1337')
|
||||||
|
|
||||||
const LocalServerScreen = () => {
|
const LocalServerScreen = () => {
|
||||||
|
const [errorRangePort, setErrorRangePort] = useState(false)
|
||||||
const [serverEnabled, setServerEnabled] = useAtom(serverEnabledAtom)
|
const [serverEnabled, setServerEnabled] = useAtom(serverEnabledAtom)
|
||||||
const showing = useAtomValue(showRightSideBarAtom)
|
const showing = useAtomValue(showRightSideBarAtom)
|
||||||
const activeModelParams = useAtomValue(getActiveThreadModelParamsAtom)
|
const activeModelParams = useAtomValue(getActiveThreadModelParamsAtom)
|
||||||
|
|
||||||
const modelEngineParams = toSettingParams(activeModelParams)
|
const modelEngineParams = toSettingParams(activeModelParams)
|
||||||
|
|
||||||
const componentDataEngineSetting = getConfigurationsData(modelEngineParams)
|
const componentDataEngineSetting = getConfigurationsData(modelEngineParams)
|
||||||
|
|
||||||
const { openServerLog, clearServerLog } = useServerLog()
|
const { openServerLog, clearServerLog } = useServerLog()
|
||||||
const { activeModel, startModel, stateModel } = useActiveModel()
|
const { startModel, stateModel } = useActiveModel()
|
||||||
const [selectedModel] = useAtom(selectedModelAtom)
|
const [selectedModel] = useAtom(selectedModelAtom)
|
||||||
|
|
||||||
const [isCorsEnabled, setIsCorsEnabled] = useAtom(corsEnabledAtom)
|
const [isCorsEnabled, setIsCorsEnabled] = useAtom(corsEnabledAtom)
|
||||||
@ -77,6 +78,15 @@ const LocalServerScreen = () => {
|
|||||||
const [firstTimeVisitAPIServer, setFirstTimeVisitAPIServer] =
|
const [firstTimeVisitAPIServer, setFirstTimeVisitAPIServer] =
|
||||||
useState<boolean>(false)
|
useState<boolean>(false)
|
||||||
|
|
||||||
|
const handleChangePort = (value: any) => {
|
||||||
|
if (Number(value) <= 0 || Number(value) >= 65536) {
|
||||||
|
setErrorRangePort(true)
|
||||||
|
} else {
|
||||||
|
setErrorRangePort(false)
|
||||||
|
}
|
||||||
|
setPort(value)
|
||||||
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (
|
if (
|
||||||
localStorage.getItem(FIRST_TIME_VISIT_API_SERVER) === null ||
|
localStorage.getItem(FIRST_TIME_VISIT_API_SERVER) === null ||
|
||||||
@ -87,6 +97,10 @@ const LocalServerScreen = () => {
|
|||||||
}
|
}
|
||||||
}, [firstTimeVisitAPIServer])
|
}, [firstTimeVisitAPIServer])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
handleChangePort(port)
|
||||||
|
}, [])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex h-full w-full">
|
<div className="flex h-full w-full">
|
||||||
{/* Left SideBar */}
|
{/* Left SideBar */}
|
||||||
@ -102,7 +116,7 @@ const LocalServerScreen = () => {
|
|||||||
<Button
|
<Button
|
||||||
block
|
block
|
||||||
themes={serverEnabled ? 'danger' : 'primary'}
|
themes={serverEnabled ? 'danger' : 'primary'}
|
||||||
disabled={stateModel.loading}
|
disabled={stateModel.loading || errorRangePort}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (serverEnabled) {
|
if (serverEnabled) {
|
||||||
window.core?.api?.stopServer()
|
window.core?.api?.stopServer()
|
||||||
@ -158,13 +172,21 @@ const LocalServerScreen = () => {
|
|||||||
</Select>
|
</Select>
|
||||||
|
|
||||||
<Input
|
<Input
|
||||||
className="w-[60px] flex-shrink-0"
|
className={twMerge(
|
||||||
|
'w-[70px] flex-shrink-0',
|
||||||
|
errorRangePort && 'border-danger'
|
||||||
|
)}
|
||||||
value={port}
|
value={port}
|
||||||
onChange={(e) => setPort(e.target.value)}
|
onChange={(e) => {
|
||||||
maxLength={4}
|
handleChangePort(e.target.value)
|
||||||
|
}}
|
||||||
|
maxLength={5}
|
||||||
disabled={serverEnabled}
|
disabled={serverEnabled}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
{errorRangePort && (
|
||||||
|
<p className="mt-2 text-xs text-danger">{`The port range should be from 0 to 65536`}</p>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<label
|
<label
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user