mirror of
https://github.com/rustfs/console.git
synced 2026-09-19 01:47:44 +08:00
- 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>
62 lines
1.6 KiB
TypeScript
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)
|
|
} |