feat: Introduce owner management functionality with a new frontend list component and supporting backend API.
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -110,6 +111,8 @@ func startServer(cfg *config.Config) {
|
||||
mux.HandleFunc("/api/db/owners", api.CORS(handleGetOwners))
|
||||
mux.HandleFunc("/api/db/owners/stats", api.CORS(handleGetOwnerStats))
|
||||
mux.HandleFunc("/api/db/owners/clear", api.CORS(handleClearOwners))
|
||||
mux.HandleFunc("/api/db/owners/delete/", api.CORS(handleDeleteOwner)) // DELETE /api/db/owners/delete/{id}
|
||||
mux.HandleFunc("/api/db/owners/batch-delete", api.CORS(handleBatchDeleteOwners)) // POST 批量删除
|
||||
mux.HandleFunc("/api/db/owners/refetch-account-ids", api.CORS(api.HandleRefetchAccountIDs))
|
||||
mux.HandleFunc("/api/upload/validate", api.CORS(api.HandleUploadValidate))
|
||||
|
||||
@@ -642,6 +645,72 @@ func handleClearOwners(w http.ResponseWriter, r *http.Request) {
|
||||
api.Success(w, map[string]string{"message": "已清空"})
|
||||
}
|
||||
|
||||
// handleDeleteOwner DELETE /api/db/owners/delete/{id} - 删除单个 owner
|
||||
func handleDeleteOwner(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodDelete && r.Method != http.MethodPost {
|
||||
api.Error(w, http.StatusMethodNotAllowed, "仅支持 DELETE/POST")
|
||||
return
|
||||
}
|
||||
|
||||
if database.Instance == nil {
|
||||
api.Error(w, http.StatusInternalServerError, "数据库未初始化")
|
||||
return
|
||||
}
|
||||
|
||||
// 从 URL 提取 ID: /api/db/owners/delete/{id}
|
||||
path := strings.TrimPrefix(r.URL.Path, "/api/db/owners/delete/")
|
||||
id, err := strconv.Atoi(path)
|
||||
if err != nil {
|
||||
api.Error(w, http.StatusBadRequest, "无效的 ID")
|
||||
return
|
||||
}
|
||||
|
||||
if err := database.Instance.DeleteTeamOwner(int64(id)); err != nil {
|
||||
api.Error(w, http.StatusInternalServerError, fmt.Sprintf("删除失败: %v", err))
|
||||
return
|
||||
}
|
||||
|
||||
api.Success(w, map[string]string{"message": "已删除"})
|
||||
}
|
||||
|
||||
// handleBatchDeleteOwners POST /api/db/owners/batch-delete - 批量删除 owners
|
||||
func handleBatchDeleteOwners(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodPost {
|
||||
api.Error(w, http.StatusMethodNotAllowed, "仅支持 POST")
|
||||
return
|
||||
}
|
||||
|
||||
if database.Instance == nil {
|
||||
api.Error(w, http.StatusInternalServerError, "数据库未初始化")
|
||||
return
|
||||
}
|
||||
|
||||
var req struct {
|
||||
IDs []int `json:"ids"`
|
||||
}
|
||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
||||
api.Error(w, http.StatusBadRequest, "请求格式错误")
|
||||
return
|
||||
}
|
||||
|
||||
if len(req.IDs) == 0 {
|
||||
api.Error(w, http.StatusBadRequest, "请选择要删除的账号")
|
||||
return
|
||||
}
|
||||
|
||||
deleted := 0
|
||||
for _, id := range req.IDs {
|
||||
if err := database.Instance.DeleteTeamOwner(int64(id)); err == nil {
|
||||
deleted++
|
||||
}
|
||||
}
|
||||
|
||||
api.Success(w, map[string]interface{}{
|
||||
"message": fmt.Sprintf("已删除 %d 个账号", deleted),
|
||||
"deleted": deleted,
|
||||
})
|
||||
}
|
||||
|
||||
// handleRegisterTest POST /api/register/test - 测试注册流程
|
||||
func handleRegisterTest(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodPost {
|
||||
|
||||
Reference in New Issue
Block a user