// 腾讯云COS配置文件
|
// 注意:这个文件包含敏感信息,在生产环境中应该通过环境变量或后端API获取
|
|
export interface COSConfig {
|
Region: string
|
Bucket: string
|
SecretId?: string
|
SecretKey?: string
|
SecurityToken?: string
|
}
|
|
// 开发环境配置(请替换为实际的配置信息)
|
export const DEV_COS_CONFIG: COSConfig = {
|
Region: 'ap-chengdu', // 成都地域
|
Bucket: 'ryc-media-1234567890', // 请替换为实际的存储桶名称
|
// 注意:在生产环境中,不应该在前端代码中直接写入密钥
|
// 应该通过后端接口获取临时密钥
|
SecretId: 'AKID_YOUR_SECRET_ID', // 请替换为实际的SecretId
|
SecretKey: 'YOUR_SECRET_KEY', // 请替换为实际的SecretKey
|
}
|
|
// 生产环境应该通过后端API获取临时密钥
|
export const getTemporaryCredentials = async (): Promise<{
|
TmpSecretId: string
|
TmpSecretKey: string
|
SecurityToken: string
|
StartTime: number
|
ExpiredTime: number
|
}> => {
|
// 这里应该调用后端API获取临时密钥
|
// 示例:
|
// const response = await fetch('/api/cos/credentials')
|
// return response.json()
|
|
// 临时返回模拟数据(仅用于开发测试)
|
return {
|
TmpSecretId: DEV_COS_CONFIG.SecretId || '',
|
TmpSecretKey: DEV_COS_CONFIG.SecretKey || '',
|
SecurityToken: DEV_COS_CONFIG.SecurityToken || '',
|
StartTime: Math.round(Date.now() / 1000),
|
ExpiredTime: Math.round(Date.now() / 1000) + 1800, // 30分钟后过期
|
}
|
}
|
|
// 文件存储目录配置
|
export const STORAGE_FOLDERS = {
|
AVATARS: 'avatars/',
|
DOCUMENTS: 'documents/',
|
IMAGES: 'images/',
|
VIDEOS: 'videos/',
|
AUDIOS: 'audios/',
|
OTHERS: 'others/'
|
} as const
|
|
// 文件大小限制(字节)
|
export const FILE_SIZE_LIMITS = {
|
IMAGE: 10 * 1024 * 1024, // 10MB
|
VIDEO: 100 * 1024 * 1024, // 100MB
|
AUDIO: 50 * 1024 * 1024, // 50MB
|
DOCUMENT: 20 * 1024 * 1024, // 20MB
|
DEFAULT: 10 * 1024 * 1024 // 10MB
|
} as const
|
|
// 支持的文件类型
|
export const SUPPORTED_FILE_TYPES = {
|
IMAGE: ['image/jpeg', 'image/png', 'image/gif', 'image/webp'],
|
VIDEO: ['video/mp4', 'video/avi', 'video/mov', 'video/wmv'],
|
AUDIO: ['audio/mp3', 'audio/wav', 'audio/aac', 'audio/ogg'],
|
DOCUMENT: [
|
'application/pdf',
|
'application/msword',
|
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
'text/plain'
|
]
|
} as const
|