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:
@@ -123,6 +123,7 @@ func startServer(cfg *config.Config) {
|
||||
mux.HandleFunc("/api/s2a/proxy/", api.CORS(handleS2AProxy)) // 通配代理
|
||||
mux.HandleFunc("/api/s2a/clean-errors", api.CORS(api.HandleCleanErrorAccounts)) // 清理错误账号
|
||||
mux.HandleFunc("/api/s2a/cleaner/settings", api.CORS(handleCleanerSettings)) // 清理服务设置
|
||||
mux.HandleFunc("/api/s2a/profiles", api.CORS(handleS2AProfiles)) // S2A 配置预设管理
|
||||
|
||||
// 统计 API
|
||||
mux.HandleFunc("/api/stats/max-rpm", api.CORS(api.HandleGetMaxRPM)) // 今日最高 RPM
|
||||
@@ -1138,6 +1139,62 @@ func handleCleanerSettings(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
// handleS2AProfiles GET/POST/DELETE /api/s2a/profiles
|
||||
func handleS2AProfiles(w http.ResponseWriter, r *http.Request) {
|
||||
if database.Instance == nil {
|
||||
api.Error(w, http.StatusInternalServerError, "数据库未初始化")
|
||||
return
|
||||
}
|
||||
|
||||
switch r.Method {
|
||||
case http.MethodGet:
|
||||
profiles, err := database.Instance.GetS2AProfiles()
|
||||
if err != nil {
|
||||
api.Error(w, http.StatusInternalServerError, fmt.Sprintf("获取配置预设失败: %v", err))
|
||||
return
|
||||
}
|
||||
// 确保 group_ids 解析为 JSON
|
||||
// (数据库层返回的是 JSON string, 这里前端可以直接用,或者我们在 Go 里转一下)
|
||||
// 由于 database.S2AProfile 定义 GroupIDs 为 string,我们直接返回即可,前端解析
|
||||
api.Success(w, profiles)
|
||||
|
||||
case http.MethodPost:
|
||||
var p database.S2AProfile
|
||||
if err := json.NewDecoder(r.Body).Decode(&p); err != nil {
|
||||
api.Error(w, http.StatusBadRequest, "请求格式错误")
|
||||
return
|
||||
}
|
||||
if p.Name == "" {
|
||||
api.Error(w, http.StatusBadRequest, "配置名称不能为空")
|
||||
return
|
||||
}
|
||||
|
||||
id, err := database.Instance.AddS2AProfile(p)
|
||||
if err != nil {
|
||||
api.Error(w, http.StatusInternalServerError, fmt.Sprintf("保存配置预设失败: %v", err))
|
||||
return
|
||||
}
|
||||
p.ID = id
|
||||
api.Success(w, p)
|
||||
|
||||
case http.MethodDelete:
|
||||
idStr := r.URL.Query().Get("id")
|
||||
id, err := strconv.ParseInt(idStr, 10, 64)
|
||||
if err != nil {
|
||||
api.Error(w, http.StatusBadRequest, "无效的 ID")
|
||||
return
|
||||
}
|
||||
if err := database.Instance.DeleteS2AProfile(id); err != nil {
|
||||
api.Error(w, http.StatusInternalServerError, fmt.Sprintf("删除配置预设失败: %v", err))
|
||||
return
|
||||
}
|
||||
api.Success(w, map[string]string{"message": "已删除"})
|
||||
|
||||
default:
|
||||
api.Error(w, http.StatusMethodNotAllowed, "不支持的方法")
|
||||
}
|
||||
}
|
||||
|
||||
// handleProxyTest POST /api/proxy/test - 测试代理连接
|
||||
func handleProxyTest(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodPost {
|
||||
|
||||
Reference in New Issue
Block a user