feat(s2a): Add S2A configuration profiles management system
- Add new `/api/s2a/profiles` endpoint supporting GET, POST, DELETE operations - Create `s2a_profiles` database table with fields for API configuration, concurrency, priority, group IDs, and proxy settings - Implement database methods: `GetS2AProfiles()`, `AddS2AProfile()`, `DeleteS2AProfile()` - Add S2AProfile struct to database models with JSON serialization support - Implement profile management UI in S2AConfig page with save, load, and delete functionality - Add profile list display with ability to apply saved configurations - Add S2AProfile type definition to frontend types - Enable users to save and reuse S2A configurations as presets for faster setup
This commit is contained in:
@@ -23,6 +23,20 @@ type TeamOwner struct {
|
||||
LastCheckedAt *time.Time `json:"last_checked_at,omitempty"`
|
||||
}
|
||||
|
||||
// S2AProfile S2A 配置预设
|
||||
type S2AProfile struct {
|
||||
ID int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
APIBase string `json:"api_base"`
|
||||
AdminKey string `json:"admin_key"`
|
||||
Concurrency int `json:"concurrency"`
|
||||
Priority int `json:"priority"`
|
||||
GroupIDs string `json:"group_ids"` // JSON array string
|
||||
ProxyEnabled bool `json:"proxy_enabled"`
|
||||
ProxyAddress string `json:"proxy_address"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
// DB 数据库管理器
|
||||
type DB struct {
|
||||
db *sql.DB
|
||||
@@ -161,6 +175,20 @@ func (d *DB) createTables() error {
|
||||
CREATE INDEX IF NOT EXISTS idx_app_logs_timestamp ON app_logs(timestamp);
|
||||
CREATE INDEX IF NOT EXISTS idx_app_logs_module ON app_logs(module);
|
||||
CREATE INDEX IF NOT EXISTS idx_app_logs_level ON app_logs(level);
|
||||
|
||||
-- S2A 配置预设表
|
||||
CREATE TABLE IF NOT EXISTS s2a_profiles (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT NOT NULL,
|
||||
api_base TEXT NOT NULL,
|
||||
admin_key TEXT NOT NULL,
|
||||
concurrency INTEGER DEFAULT 2,
|
||||
priority INTEGER DEFAULT 0,
|
||||
group_ids TEXT,
|
||||
proxy_enabled INTEGER DEFAULT 0,
|
||||
proxy_address TEXT,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
`)
|
||||
return err
|
||||
}
|
||||
@@ -1260,3 +1288,51 @@ func (d *DB) Close() error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetS2AProfiles 获取所有 S2A 配置预设
|
||||
func (d *DB) GetS2AProfiles() ([]S2AProfile, error) {
|
||||
rows, err := d.db.Query(`
|
||||
SELECT id, name, api_base, admin_key, concurrency, priority, group_ids, proxy_enabled, proxy_address, created_at
|
||||
FROM s2a_profiles
|
||||
ORDER BY created_at DESC
|
||||
`)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var profiles []S2AProfile
|
||||
for rows.Next() {
|
||||
var p S2AProfile
|
||||
var proxyEnabled int
|
||||
err := rows.Scan(&p.ID, &p.Name, &p.APIBase, &p.AdminKey, &p.Concurrency, &p.Priority, &p.GroupIDs, &proxyEnabled, &p.ProxyAddress, &p.CreatedAt)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
p.ProxyEnabled = proxyEnabled == 1
|
||||
profiles = append(profiles, p)
|
||||
}
|
||||
return profiles, nil
|
||||
}
|
||||
|
||||
// AddS2AProfile 添加 S2A 配置预设
|
||||
func (d *DB) AddS2AProfile(p S2AProfile) (int64, error) {
|
||||
proxyEnabled := 0
|
||||
if p.ProxyEnabled {
|
||||
proxyEnabled = 1
|
||||
}
|
||||
result, err := d.db.Exec(`
|
||||
INSERT INTO s2a_profiles (name, api_base, admin_key, concurrency, priority, group_ids, proxy_enabled, proxy_address, created_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP)
|
||||
`, p.Name, p.APIBase, p.AdminKey, p.Concurrency, p.Priority, p.GroupIDs, proxyEnabled, p.ProxyAddress)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.LastInsertId()
|
||||
}
|
||||
|
||||
// DeleteS2AProfile 删除 S2A 配置预设
|
||||
func (d *DB) DeleteS2AProfile(id int64) error {
|
||||
_, err := d.db.Exec("DELETE FROM s2a_profiles WHERE id = ?", id)
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user