Add media proxy feature for resource downloading
- Introduced a new API endpoint `GET /api/v1/video/proxy` to facilitate media resource downloads, allowing users to bypass domain restrictions imposed by WeChat. - Updated configuration to include proxy settings such as `SHORT_VIDEO_PROXY_ENABLED`, `SHORT_VIDEO_PROXY_ALLOWED_DOMAINS`, `SHORT_VIDEO_PROXY_MAX_SIZE_MB`, and `SHORT_VIDEO_PROXY_TIMEOUT_SECONDS`. - Enhanced the `ShortVideoConfig` struct to accommodate new proxy-related fields. - Improved error handling for proxy requests, including checks for allowed domains and file size limits. - Updated documentation to reflect the new proxy functionality and its configuration options, ensuring clarity for users and developers.
This commit is contained in:
+37
-3
@@ -49,6 +49,11 @@ type ShortVideoConfig struct {
|
||||
APIKey string
|
||||
FreeDailyQuota int
|
||||
RequestTimeout time.Duration
|
||||
// 代理相关配置
|
||||
ProxyEnabled bool // 是否启用媒体代理
|
||||
ProxyAllowedDomains []string // 允许代理的域名白名单(为空表示允许所有)
|
||||
ProxyMaxSize int64 // 代理文件最大大小(字节),0 表示不限制
|
||||
ProxyTimeout time.Duration // 代理请求超时时间
|
||||
}
|
||||
|
||||
// AIConfig 用于“AI 建议/问答”等能力的通用配置(OpenAI-compatible)。
|
||||
@@ -122,9 +127,13 @@ func LoadConfig() {
|
||||
Expire: 86400, // 24小时
|
||||
},
|
||||
ShortVideo: ShortVideoConfig{
|
||||
APIKey: getEnv("SHORT_VIDEO_API_KEY", ""),
|
||||
FreeDailyQuota: getEnvAsInt("SHORT_VIDEO_FREE_QUOTA", 20),
|
||||
RequestTimeout: time.Duration(getEnvAsInt("SHORT_VIDEO_TIMEOUT_SECONDS", 5)) * time.Second,
|
||||
APIKey: getEnv("SHORT_VIDEO_API_KEY", ""),
|
||||
FreeDailyQuota: getEnvAsInt("SHORT_VIDEO_FREE_QUOTA", 20),
|
||||
RequestTimeout: time.Duration(getEnvAsInt("SHORT_VIDEO_TIMEOUT_SECONDS", 5)) * time.Second,
|
||||
ProxyEnabled: getEnvAsBool("SHORT_VIDEO_PROXY_ENABLED", true),
|
||||
ProxyAllowedDomains: getEnvAsStringSlice("SHORT_VIDEO_PROXY_ALLOWED_DOMAINS", nil),
|
||||
ProxyMaxSize: int64(getEnvAsInt("SHORT_VIDEO_PROXY_MAX_SIZE_MB", 100)) * 1024 * 1024,
|
||||
ProxyTimeout: time.Duration(getEnvAsInt("SHORT_VIDEO_PROXY_TIMEOUT_SECONDS", 60)) * time.Second,
|
||||
},
|
||||
AI: AIConfig{
|
||||
BaseURL: getEnv("AI_BASE_URL", "https://api.openai.com/v1"),
|
||||
@@ -198,3 +207,28 @@ func getEnvAsInt(key string, defaultValue int) int {
|
||||
}
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
func getEnvAsBool(key string, defaultValue bool) bool {
|
||||
if value := os.Getenv(key); value != "" {
|
||||
v := strings.ToLower(value)
|
||||
return v == "true" || v == "1" || v == "yes"
|
||||
}
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
func getEnvAsStringSlice(key string, defaultValue []string) []string {
|
||||
if value := os.Getenv(key); value != "" {
|
||||
parts := strings.Split(value, ",")
|
||||
result := make([]string, 0, len(parts))
|
||||
for _, part := range parts {
|
||||
trimmed := strings.TrimSpace(part)
|
||||
if trimmed != "" {
|
||||
result = append(result, trimmed)
|
||||
}
|
||||
}
|
||||
if len(result) > 0 {
|
||||
return result
|
||||
}
|
||||
}
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user