lrj
2 天以前 c61d4fe27c97d2ecc907756aa571a4ef14a7b9b6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// 腾讯云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