mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-31 08:29:07 +08:00
feat: make API server default to closed/disabled (#8691)
* ✨ feat: make API server default to closed/disabled - Add `enabled` field to ApiServerConfig interface with default value false - Update Redux store to include apiServer.enabled setting (defaults to false) - Add setApiServerEnabled action to control server state - Modify main process to only auto-start API server if explicitly enabled - Update UI to show enable/disable toggle in API server settings - Add migrations to handle existing configurations - Server controls now only visible when API server is enabled The API server will no longer start automatically on application launch unless explicitly enabled by the user through the settings interface. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * 🔧 chore: improve build and lint commands - Move typecheck and i18n checks to lint command for better developer experience - Simplify build:check to focus on linting and testing - Ensure all quality checks run together during development 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
parent
7ae7f13ad1
commit
eb4f218c7d
@ -28,7 +28,7 @@
|
||||
"dev": "dotenv electron-vite dev",
|
||||
"debug": "electron-vite -- --inspect --sourcemap --remote-debugging-port=9222",
|
||||
"build": "npm run typecheck && electron-vite build",
|
||||
"build:check": "yarn typecheck && yarn check:i18n && yarn test",
|
||||
"build:check": "yarn lint && yarn test",
|
||||
"build:unpack": "dotenv npm run build && electron-builder --dir",
|
||||
"build:win": "dotenv npm run build && electron-builder --win --x64 --arm64",
|
||||
"build:win:x64": "dotenv npm run build && electron-builder --win --x64",
|
||||
@ -66,7 +66,7 @@
|
||||
"test:lint": "eslint . --ext .js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts",
|
||||
"test:scripts": "vitest scripts",
|
||||
"format": "prettier --write .",
|
||||
"lint": "eslint . --ext .js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix",
|
||||
"lint": "eslint . --ext .js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix && yarn typecheck && yarn check:i18n",
|
||||
"prepare": "git config blame.ignoreRevsFile .git-blame-ignore-revs && husky"
|
||||
},
|
||||
"dependencies": {
|
||||
|
||||
@ -22,12 +22,14 @@ class ConfigManager {
|
||||
})
|
||||
|
||||
this._config = {
|
||||
enabled: settings?.apiServer?.enabled ?? false,
|
||||
port: settings?.apiServer?.port ?? 23333,
|
||||
host: 'localhost',
|
||||
apiKey: generatedKey
|
||||
}
|
||||
} else {
|
||||
this._config = {
|
||||
enabled: settings?.apiServer?.enabled ?? false,
|
||||
port: settings?.apiServer?.port ?? 23333,
|
||||
host: 'localhost',
|
||||
apiKey: settings.apiServer.apiKey
|
||||
@ -38,6 +40,7 @@ class ConfigManager {
|
||||
} catch (error: any) {
|
||||
logger.warn('Failed to load config from Redux, using defaults:', error)
|
||||
this._config = {
|
||||
enabled: false,
|
||||
port: 23333,
|
||||
host: 'localhost',
|
||||
apiKey: `cs-sk-${uuidv4()}`
|
||||
|
||||
@ -143,9 +143,13 @@ if (!app.requestSingleInstanceLock()) {
|
||||
|
||||
// Start API server if enabled
|
||||
try {
|
||||
await apiServerService.start()
|
||||
const config = await apiServerService.getCurrentConfig()
|
||||
logger.info('API server config:', config)
|
||||
if (config.enabled) {
|
||||
await apiServerService.start()
|
||||
}
|
||||
} catch (error: any) {
|
||||
logger.error('Failed to start API server:', error)
|
||||
logger.error('Failed to check/start API server:', error)
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { useTheme } from '@renderer/context/ThemeProvider'
|
||||
import { loggerService } from '@renderer/services/LoggerService'
|
||||
import { RootState, useAppDispatch } from '@renderer/store'
|
||||
import { setApiServerApiKey, setApiServerPort } from '@renderer/store/settings'
|
||||
import { setApiServerApiKey, setApiServerEnabled, setApiServerPort } from '@renderer/store/settings'
|
||||
import { IpcChannel } from '@shared/IpcChannel'
|
||||
import { Button, Input, InputNumber, Tooltip, Typography } from 'antd'
|
||||
import { Copy, ExternalLink, Play, RotateCcw, Square } from 'lucide-react'
|
||||
@ -64,6 +64,7 @@ const ApiServerSettings: FC = () => {
|
||||
} catch (error) {
|
||||
window.message.error(t('apiServer.messages.operationFailed') + (error as Error).message)
|
||||
} finally {
|
||||
dispatch(setApiServerEnabled(enabled))
|
||||
setApiServerLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1925,6 +1925,7 @@ const migrateConfig = {
|
||||
// Initialize API server configuration if not present
|
||||
if (!state.settings.apiServer) {
|
||||
state.settings.apiServer = {
|
||||
enabled: false,
|
||||
host: 'localhost',
|
||||
port: 23333,
|
||||
apiKey: `cs-sk-${uuid()}`
|
||||
|
||||
@ -382,6 +382,7 @@ export const initialState: SettingsState = {
|
||||
navbarPosition: 'left',
|
||||
// API Server
|
||||
apiServer: {
|
||||
enabled: false,
|
||||
host: 'localhost',
|
||||
port: 23333,
|
||||
apiKey: `cs-sk-${uuid()}`
|
||||
@ -791,6 +792,12 @@ const settingsSlice = createSlice({
|
||||
state.navbarPosition = action.payload
|
||||
},
|
||||
// API Server actions
|
||||
setApiServerEnabled: (state, action: PayloadAction<boolean>) => {
|
||||
state.apiServer = {
|
||||
...state.apiServer,
|
||||
enabled: action.payload
|
||||
}
|
||||
},
|
||||
setApiServerPort: (state, action: PayloadAction<number>) => {
|
||||
state.apiServer = {
|
||||
...state.apiServer,
|
||||
@ -926,6 +933,7 @@ export const {
|
||||
setEnableDeveloperMode,
|
||||
setNavbarPosition,
|
||||
// API Server actions
|
||||
setApiServerEnabled,
|
||||
setApiServerPort,
|
||||
setApiServerApiKey
|
||||
} = settingsSlice.actions
|
||||
|
||||
@ -842,6 +842,7 @@ export type S3Config = {
|
||||
export type { Message } from './newMessage'
|
||||
|
||||
export interface ApiServerConfig {
|
||||
enabled: boolean
|
||||
host: string
|
||||
port: number
|
||||
apiKey: string
|
||||
|
||||
Loading…
Reference in New Issue
Block a user