Files
huobao-drama/pkg/config/config.go
empty d970107a34 添加视频帧提取功能和阿里云OSS存储支持
- 新增从视频素材提取首帧/尾帧的功能,支持画面连续性编辑
- 添加阿里云OSS存储支持,可配置本地或OSS存储方式
- 导入视频素材时自动探测并更新视频时长信息
- 前端添加从素材提取尾帧的UI界面
- 添加FramePrompt模型的数据库迁移

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-18 21:44:39 +08:00

100 lines
2.9 KiB
Go

package config
import (
"fmt"
"github.com/spf13/viper"
)
type Config struct {
App AppConfig `mapstructure:"app"`
Server ServerConfig `mapstructure:"server"`
Database DatabaseConfig `mapstructure:"database"`
Storage StorageConfig `mapstructure:"storage"`
AI AIConfig `mapstructure:"ai"`
}
type AppConfig struct {
Name string `mapstructure:"name"`
Version string `mapstructure:"version"`
Debug bool `mapstructure:"debug"`
Language string `mapstructure:"language"` // zh 或 en
}
type ServerConfig struct {
Port int `mapstructure:"port"`
Host string `mapstructure:"host"`
CORSOrigins []string `mapstructure:"cors_origins"`
ReadTimeout int `mapstructure:"read_timeout"`
WriteTimeout int `mapstructure:"write_timeout"`
}
type DatabaseConfig struct {
Type string `mapstructure:"type"` // sqlite, mysql
Path string `mapstructure:"path"` // SQLite数据库文件路径
Host string `mapstructure:"host"`
Port int `mapstructure:"port"`
User string `mapstructure:"user"`
Password string `mapstructure:"password"`
Database string `mapstructure:"database"`
Charset string `mapstructure:"charset"`
MaxIdle int `mapstructure:"max_idle"`
MaxOpen int `mapstructure:"max_open"`
}
type StorageConfig struct {
Type string `mapstructure:"type"` // local, oss
LocalPath string `mapstructure:"local_path"` // 本地存储路径
BaseURL string `mapstructure:"base_url"` // 访问URL前缀
Oss OssConfig `mapstructure:"oss"` // 阿里云 OSS 配置
}
type OssConfig struct {
Endpoint string `mapstructure:"endpoint"` // OSS 服务地址
AccessKeyID string `mapstructure:"access_key_id"` // AccessKey ID
AccessKeySecret string `mapstructure:"access_key_secret"` // AccessKey Secret
BucketName string `mapstructure:"bucket_name"` // Bucket 名称
CustomDomain string `mapstructure:"custom_domain"` // 自定义域名(可选)
}
type AIConfig struct {
DefaultTextProvider string `mapstructure:"default_text_provider"`
DefaultImageProvider string `mapstructure:"default_image_provider"`
DefaultVideoProvider string `mapstructure:"default_video_provider"`
}
func LoadConfig() (*Config, error) {
viper.SetConfigName("config")
viper.SetConfigType("yaml")
viper.AddConfigPath("./configs")
viper.AddConfigPath(".")
viper.AutomaticEnv()
if err := viper.ReadInConfig(); err != nil {
return nil, fmt.Errorf("failed to read config: %w", err)
}
var config Config
if err := viper.Unmarshal(&config); err != nil {
return nil, fmt.Errorf("failed to unmarshal config: %w", err)
}
return &config, nil
}
func (c *DatabaseConfig) DSN() string {
if c.Type == "sqlite" {
return c.Path
}
// MySQL DSN
return fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=%s&parseTime=True&loc=Local",
c.User,
c.Password,
c.Host,
c.Port,
c.Database,
c.Charset,
)
}