Files
rustfs-console/utils/config-helpers.ts
T
overtrueandClaude de0f2c550d feat: improve TypeScript type safety and code quality
- Added comprehensive TypeScript type definitions for app configuration
- Fixed type safety issues in sidebar component with proper type casting
- Improved code organization with better file naming conventions
- Enhanced error handling with centralized error management
- Added performance optimizations with caching and code splitting
- Improved development experience with better tooling configuration
- Updated project documentation with comprehensive README
- Added proper type definitions for navigation items and app config
- Fixed licensing information and added proper Apache 2.0 license

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-10 23:19:22 +08:00

62 lines
1.6 KiB
TypeScript

import type { SiteConfig } from '~/types/config'
import { logger } from './logger'
/**
* 创建默认配置
*/
export const createDefaultConfig = (serverHost: string): SiteConfig => {
return {
serverHost,
api: {
baseURL: `${serverHost}/rustfs/admin/v3`
},
s3: {
endpoint: serverHost,
region: 'us-east-1',
accessKeyId: '',
secretAccessKey: ''
}
}
}
/**
* 从localStorage获取保存的主机配置
*/
export const getStoredHostConfig = (): SiteConfig | null => {
if (typeof window === 'undefined') return null
const savedHost = localStorage.getItem('rustfs-server-host')
if (!savedHost) return null
try {
const url = new URL(savedHost)
const serverHost = `${url.protocol}//${url.host}`
return createDefaultConfig(serverHost)
} catch (error) {
logger.warn('Invalid saved host configuration:', error)
return null
}
}
/**
* 获取当前浏览器主机配置
*/
export const getCurrentBrowserConfig = (): SiteConfig | null => {
if (typeof window === 'undefined') return null
const currentHost = window.location.host
const protocol = window.location.protocol.replace(':', '')
const serverHost = `${protocol}://${currentHost}`
return createDefaultConfig(serverHost)
}
/**
* 获取服务端默认配置
*/
export const getServerDefaultConfig = (): SiteConfig => {
// 注意:这里按照用户要求,服务端也应该尽量使用当前host
// 但由于服务端限制,只能使用localhost作为fallback
const defaultServerHost = 'http://localhost:9000'
return createDefaultConfig(defaultServerHost)
}