mirror of
https://github.com/black-ant/Ant-Browser.git
synced 2026-07-14 18:48:55 +08:00
channel: master
version: 1.2.0
source-ref: D:\code\open_source\ant-chrome master
source-commit: f3d7ec5
merged-public-base: 3d264eb
80 lines
2.5 KiB
Go
80 lines
2.5 KiB
Go
package browser
|
|
|
|
import (
|
|
"ant-chrome/backend/internal/logger"
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
// Update 更新配置
|
|
func (m *Manager) Update(profileId string, input ProfileInput) (*Profile, error) {
|
|
log := logger.New("Browser")
|
|
m.InitData()
|
|
m.Mutex.Lock()
|
|
defer m.Mutex.Unlock()
|
|
|
|
profile, exists := m.Profiles[profileId]
|
|
if !exists {
|
|
log.Error("浏览器配置不存在", logger.F("profile_id", profileId))
|
|
return nil, fmt.Errorf("profile not found")
|
|
}
|
|
resolvedProxy, err := m.resolveProfileProxyInput(input.ProxyId, input.ProxyConfig)
|
|
if err != nil {
|
|
log.Error("代理绑定失败", logger.F("profile_id", profileId), logger.F("proxy_id", strings.TrimSpace(input.ProxyId)), logger.F("error", err.Error()))
|
|
return nil, err
|
|
}
|
|
|
|
profile.ProfileName = input.ProfileName
|
|
profile.UserDataDir = input.UserDataDir
|
|
profile.CoreId = normalizeProfileCoreID(input.CoreId)
|
|
profile.FingerprintArgs = input.FingerprintArgs
|
|
if resolvedProxy.HasSelectedProxy {
|
|
_ = BindProfileToProxy(profile, resolvedProxy.SelectedProxy, true)
|
|
} else if resolvedProxy.FallbackToDirect {
|
|
_ = m.bindProfileToDirectProxy(profile)
|
|
} else {
|
|
profile.ProxyId = resolvedProxy.ProxyId
|
|
profile.ProxyConfig = resolvedProxy.ProxyConfig
|
|
_ = ClearProfileProxyBinding(profile)
|
|
}
|
|
if resolvedProxy.UsedConfigFallback {
|
|
log.Warn("代理ID未命中,已改为使用输入的代理配置",
|
|
logger.F("profile_id", profileId),
|
|
logger.F("proxy_id", strings.TrimSpace(input.ProxyId)),
|
|
)
|
|
}
|
|
profile.LaunchArgs = input.LaunchArgs
|
|
profile.Tags = input.Tags
|
|
profile.Keywords = append([]string{}, input.Keywords...)
|
|
profile.GroupId = buildProfileGroupID(input.GroupId)
|
|
profile.UpdatedAt = time.Now().Format(time.RFC3339)
|
|
|
|
log.Info("浏览器配置更新", logger.F("profile_id", profileId), logger.F("profile_name", input.ProfileName))
|
|
if err := m.SaveProfiles(); err != nil {
|
|
return nil, err
|
|
}
|
|
return profile, nil
|
|
}
|
|
|
|
// SetKeywords 设置实例关键字(独立接口,不影响其他字段)
|
|
func (m *Manager) SetKeywords(profileId string, keywords []string) (*Profile, error) {
|
|
log := logger.New("Browser")
|
|
m.InitData()
|
|
m.Mutex.Lock()
|
|
defer m.Mutex.Unlock()
|
|
|
|
profile, exists := m.Profiles[profileId]
|
|
if !exists {
|
|
return nil, fmt.Errorf("profile not found")
|
|
}
|
|
profile.Keywords = append([]string{}, keywords...)
|
|
profile.UpdatedAt = time.Now().Format(time.RFC3339)
|
|
|
|
log.Info("关键字更新", logger.F("profile_id", profileId))
|
|
if err := m.SaveProfiles(); err != nil {
|
|
return nil, err
|
|
}
|
|
return profile, nil
|
|
}
|