feat: 平台配置唯一ID — PlatformConfig.ID + adapter全链路传播

- PlatformConfig 新增 ID 字段 (8字节hex,创建时自动生成)
- QQ adapter 新增 configID + ConfigID() 访问器
- ChannelInfo 新增 AdapterID + AdapterName
- createSingleAdapter 接受 configID 参数
- 同一个平台类型的多个配置实例通过 ID 唯一区分

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2026-06-23 17:59:37 +08:00
parent 6bf59f7eee
commit 45fac267fe
8 changed files with 177 additions and 9 deletions
@@ -1,6 +1,8 @@
package config
import (
"crypto/rand"
"encoding/hex"
"encoding/json"
"fmt"
"os"
@@ -10,11 +12,13 @@ import (
// PlatformConfig holds persistent configuration for one platform adapter.
type PlatformConfig struct {
Name string `json:"name"`
Platform string `json:"platform"` // base platform type: "qq", "telegram", etc.
ID string `json:"id"` // immutable unique ID, generated at creation
Name string `json:"name"` // config key, e.g. "qq-main", "qq-work"
Platform string `json:"platform"` // base platform type: "qq", "telegram", etc.
Enabled bool `json:"enabled"`
Label string `json:"label"`
Fields map[string]string `json:"fields"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
@@ -102,11 +106,22 @@ func (s *Store) Set(cfg PlatformConfig) error {
if cfg.Fields == nil {
cfg.Fields = make(map[string]string)
}
// Generate stable ID for new configs.
if cfg.ID == "" {
cfg.ID = generateConfigID()
cfg.CreatedAt = time.Now()
}
cfg.UpdatedAt = time.Now()
s.configs[cfg.Name] = &cfg
return s.save()
}
func generateConfigID() string {
b := make([]byte, 8)
rand.Read(b)
return hex.EncodeToString(b)
}
// Delete removes a platform config and persists.
func (s *Store) Delete(name string) error {
s.mu.Lock()