mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-11-20 15:06:36 +00:00
feat(sora): add Google Drive storage backend with unified storage abstraction
- Define SoraObjectStorage interface abstracting S3 and GDrive backends - Implement SoraGDriveStorage with OAuth2 and Service Account auth - Add SoraStorageRouter to route requests based on active profile provider - Add GDrive OAuth handler for authorization flow (start + callback) - Extend profile model with provider, auth_type, and GDrive-specific fields - Update frontend UI with provider selection, dynamic form fields, and i18n - Migrate API paths from /sora-s3 to /sora-storage (old paths preserved) - All existing S3 functionality remains backward compatible Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
a9ecd7bcc6
commit
ad54040c07
26 files changed
+1711
-280
No files matched your search
@@ -186,6 +186,49 @@ func (s *SettingService) SetOnS3UpdateCallback(callback func()) {
|
||||
s.onS3Update = callback
|
||||
}
|
||||
|
||||
// SetOnStorageUpdateCallback 设置存储配置变更时的回调函数(用于刷新所有存储客户端缓存)。
|
||||
// 替代 SetOnS3UpdateCallback,支持 S3 + GDrive 统一刷新。
|
||||
func (s *SettingService) SetOnStorageUpdateCallback(callback func()) {
|
||||
s.onS3Update = callback
|
||||
}
|
||||
|
||||
// --- 统一存储 Profile 方法别名 ---
|
||||
|
||||
// ListSoraStorageProfiles 获取 Sora 存储多配置列表(统一方法名)。
|
||||
func (s *SettingService) ListSoraStorageProfiles(ctx context.Context) (*SoraS3ProfileList, error) {
|
||||
return s.ListSoraS3Profiles(ctx)
|
||||
}
|
||||
|
||||
// CreateSoraStorageProfile 创建 Sora 存储配置(统一方法名)。
|
||||
func (s *SettingService) CreateSoraStorageProfile(ctx context.Context, profile *SoraS3Profile, setActive bool) (*SoraS3Profile, error) {
|
||||
return s.CreateSoraS3Profile(ctx, profile, setActive)
|
||||
}
|
||||
|
||||
// UpdateSoraStorageProfile 更新 Sora 存储配置(统一方法名)。
|
||||
func (s *SettingService) UpdateSoraStorageProfile(ctx context.Context, profileID string, profile *SoraS3Profile) (*SoraS3Profile, error) {
|
||||
return s.UpdateSoraS3Profile(ctx, profileID, profile)
|
||||
}
|
||||
|
||||
// DeleteSoraStorageProfile 删除 Sora 存储配置(统一方法名)。
|
||||
func (s *SettingService) DeleteSoraStorageProfile(ctx context.Context, profileID string) error {
|
||||
return s.DeleteSoraS3Profile(ctx, profileID)
|
||||
}
|
||||
|
||||
// SetActiveSoraStorageProfile 设置激活的 Sora 存储配置(统一方法名)。
|
||||
func (s *SettingService) SetActiveSoraStorageProfile(ctx context.Context, profileID string) (*SoraS3Profile, error) {
|
||||
return s.SetActiveSoraS3Profile(ctx, profileID)
|
||||
}
|
||||
|
||||
// GetActiveStorageProfile 获取当前激活的存储配置 profile。
|
||||
func (s *SettingService) GetActiveStorageProfile(ctx context.Context) (*SoraS3Profile, error) {
|
||||
profiles, err := s.ListSoraS3Profiles(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
active := pickActiveSoraS3Profile(profiles.Items, profiles.ActiveProfileID)
|
||||
return active, nil
|
||||
}
|
||||
|
||||
// SetVersion sets the application version for injection into public settings
|
||||
func (s *SettingService) SetVersion(version string) {
|
||||
s.version = version
|
||||
@@ -1234,6 +1277,8 @@ type soraS3ProfilesStore struct {
|
||||
type soraS3ProfileStoreItem struct {
|
||||
ProfileID string `json:"profile_id"`
|
||||
Name string `json:"name"`
|
||||
Provider string `json:"provider,omitempty"` // "s3" / "gdrive",空值视为 "s3"
|
||||
AccessMode string `json:"access_mode,omitempty"` // "direct" / "proxy",空值视为 "direct"
|
||||
Enabled bool `json:"enabled"`
|
||||
Endpoint string `json:"endpoint"`
|
||||
Region string `json:"region"`
|
||||
@@ -1245,6 +1290,14 @@ type soraS3ProfileStoreItem struct {
|
||||
CDNURL string `json:"cdn_url"`
|
||||
DefaultStorageQuotaBytes int64 `json:"default_storage_quota_bytes"`
|
||||
UpdatedAt string `json:"updated_at"`
|
||||
|
||||
// --- Google Drive 专属 ---
|
||||
AuthType string `json:"auth_type,omitempty"`
|
||||
ClientID string `json:"client_id,omitempty"`
|
||||
ClientSecret string `json:"client_secret,omitempty"`
|
||||
RefreshToken string `json:"refresh_token,omitempty"`
|
||||
ServiceAccountJSON string `json:"service_account_json,omitempty"`
|
||||
FolderID string `json:"folder_id,omitempty"`
|
||||
}
|
||||
|
||||
// GetSoraS3Settings 获取 Sora S3 存储配置(兼容旧单配置语义:返回当前激活配置)
|
||||
@@ -1356,6 +1409,8 @@ func (s *SettingService) CreateSoraS3Profile(ctx context.Context, profile *SoraS
|
||||
store.Items = append(store.Items, soraS3ProfileStoreItem{
|
||||
ProfileID: profileID,
|
||||
Name: name,
|
||||
Provider: profile.Provider,
|
||||
AccessMode: profile.AccessMode,
|
||||
Enabled: profile.Enabled,
|
||||
Endpoint: strings.TrimSpace(profile.Endpoint),
|
||||
Region: strings.TrimSpace(profile.Region),
|
||||
@@ -1367,6 +1422,13 @@ func (s *SettingService) CreateSoraS3Profile(ctx context.Context, profile *SoraS
|
||||
CDNURL: strings.TrimSpace(profile.CDNURL),
|
||||
DefaultStorageQuotaBytes: maxInt64(profile.DefaultStorageQuotaBytes, 0),
|
||||
UpdatedAt: now,
|
||||
// Google Drive 专属
|
||||
AuthType: profile.AuthType,
|
||||
ClientID: strings.TrimSpace(profile.ClientID),
|
||||
ClientSecret: profile.ClientSecret,
|
||||
RefreshToken: profile.RefreshToken,
|
||||
ServiceAccountJSON: profile.ServiceAccountJSON,
|
||||
FolderID: strings.TrimSpace(profile.FolderID),
|
||||
})
|
||||
|
||||
if setActive || store.ActiveProfileID == "" {
|
||||
@@ -1412,6 +1474,8 @@ func (s *SettingService) UpdateSoraS3Profile(ctx context.Context, profileID stri
|
||||
return nil, infraerrors.BadRequest("SORA_S3_PROFILE_NAME_REQUIRED", "name is required")
|
||||
}
|
||||
target.Name = name
|
||||
target.Provider = profile.Provider
|
||||
target.AccessMode = profile.AccessMode
|
||||
target.Enabled = profile.Enabled
|
||||
target.Endpoint = strings.TrimSpace(profile.Endpoint)
|
||||
target.Region = strings.TrimSpace(profile.Region)
|
||||
@@ -1424,6 +1488,19 @@ func (s *SettingService) UpdateSoraS3Profile(ctx context.Context, profileID stri
|
||||
if profile.SecretAccessKey != "" {
|
||||
target.SecretAccessKey = profile.SecretAccessKey
|
||||
}
|
||||
// Google Drive 专属
|
||||
target.AuthType = profile.AuthType
|
||||
target.ClientID = strings.TrimSpace(profile.ClientID)
|
||||
if profile.ClientSecret != "" {
|
||||
target.ClientSecret = profile.ClientSecret
|
||||
}
|
||||
if profile.RefreshToken != "" {
|
||||
target.RefreshToken = profile.RefreshToken
|
||||
}
|
||||
if profile.ServiceAccountJSON != "" {
|
||||
target.ServiceAccountJSON = profile.ServiceAccountJSON
|
||||
}
|
||||
target.FolderID = strings.TrimSpace(profile.FolderID)
|
||||
target.UpdatedAt = time.Now().UTC().Format(time.RFC3339)
|
||||
store.Items[targetIndex] = target
|
||||
|
||||
@@ -1726,6 +1803,8 @@ func convertSoraS3ProfilesStore(store *soraS3ProfilesStore) *SoraS3ProfileList {
|
||||
ProfileID: item.ProfileID,
|
||||
Name: item.Name,
|
||||
IsActive: item.ProfileID == store.ActiveProfileID,
|
||||
Provider: item.Provider,
|
||||
AccessMode: item.AccessMode,
|
||||
Enabled: item.Enabled,
|
||||
Endpoint: item.Endpoint,
|
||||
Region: item.Region,
|
||||
@@ -1738,6 +1817,16 @@ func convertSoraS3ProfilesStore(store *soraS3ProfilesStore) *SoraS3ProfileList {
|
||||
CDNURL: item.CDNURL,
|
||||
DefaultStorageQuotaBytes: item.DefaultStorageQuotaBytes,
|
||||
UpdatedAt: item.UpdatedAt,
|
||||
// Google Drive 专属
|
||||
AuthType: item.AuthType,
|
||||
ClientID: item.ClientID,
|
||||
ClientSecret: item.ClientSecret,
|
||||
ClientSecretConfigured: item.ClientSecret != "",
|
||||
RefreshToken: item.RefreshToken,
|
||||
RefreshTokenConfigured: item.RefreshToken != "",
|
||||
ServiceAccountJSON: item.ServiceAccountJSON,
|
||||
ServiceAccountConfigured: item.ServiceAccountJSON != "",
|
||||
FolderID: item.FolderID,
|
||||
})
|
||||
}
|
||||
return &SoraS3ProfileList{
|
||||
|
||||
Reference in new issue
Block a user