mirror of
https://github.com/truewhile/MeBox.git
synced 2026-09-29 11:36:36 +08:00
63 lines
2.6 KiB
Go
63 lines
2.6 KiB
Go
// Package model 定义第三方 API 配置数据模型。
|
|
package model
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// ApiConfig 存储第三方 API 密钥和配置信息。
|
|
// APIKey 字段在 JSON 序列化时隐藏(json:"-"),通过加密存储。
|
|
type ApiConfig struct {
|
|
ID string `gorm:"primaryKey;size:36" json:"id"`
|
|
Provider string `gorm:"size:64;uniqueIndex;not null" json:"provider"`
|
|
APIKey string `gorm:"size:512" json:"-"`
|
|
BaseURL string `gorm:"size:512" json:"base_url,omitempty"`
|
|
Extra string `gorm:"type:text" json:"extra,omitempty"`
|
|
Enabled bool `gorm:"default:true" json:"enabled"`
|
|
Description string `gorm:"size:255" json:"description,omitempty"`
|
|
LastTestedAt *time.Time `json:"last_tested_at,omitempty"`
|
|
TestResult string `gorm:"size:32" json:"test_result,omitempty"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
// BeforeCreate 生成 UUID。
|
|
func (c *ApiConfig) BeforeCreate(_ *gorm.DB) error {
|
|
if c.ID == "" {
|
|
c.ID = uuid.NewString()
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// BeforeUpdate 更新时间戳。
|
|
func (c *ApiConfig) BeforeUpdate(_ *gorm.DB) error {
|
|
c.UpdatedAt = time.Now()
|
|
return nil
|
|
}
|
|
|
|
// ApiProvider 定义支持的 API 提供者列表。
|
|
type ApiProvider struct {
|
|
ID string `json:"id"`
|
|
Name string `json:"name"`
|
|
Description string `json:"description"`
|
|
HasAPIKey bool `json:"has_api_key"`
|
|
HasBaseURL bool `json:"has_base_url"`
|
|
}
|
|
|
|
// PredefinedProviders 返回预定义的 API 提供者列表。
|
|
func PredefinedProviders() []ApiProvider {
|
|
return []ApiProvider{
|
|
{ID: "tmdb", Name: "TMDb", Description: "The Movie Database - 电影/剧集元数据", HasAPIKey: true, HasBaseURL: true},
|
|
{ID: "douban", Name: "豆瓣", Description: "豆瓣电影/音乐/书籍数据", HasAPIKey: true, HasBaseURL: false},
|
|
{ID: "bangumi", Name: "Bangumi", Description: "番剧/动漫数据库", HasAPIKey: true, HasBaseURL: false},
|
|
{ID: "thetvdb", Name: "TheTVDB", Description: "TV Series Database", HasAPIKey: true, HasBaseURL: false},
|
|
{ID: "fanart", Name: "Fanart.tv", Description: "影视海报/背景图", HasAPIKey: true, HasBaseURL: false},
|
|
{ID: "openai", Name: "OpenAI", Description: "GPT 系列模型", HasAPIKey: true, HasBaseURL: true},
|
|
{ID: "deepseek", Name: "DeepSeek", Description: "DeepSeek 大模型", HasAPIKey: true, HasBaseURL: true},
|
|
{ID: "siliconflow", Name: "SiliconFlow", Description: "AI 模型聚合 API", HasAPIKey: true, HasBaseURL: true},
|
|
{ID: "adult", Name: "Adult API", Description: "Adult 内容元数据(需额外权限)", HasAPIKey: true, HasBaseURL: false},
|
|
}
|
|
}
|