This commit is contained in:
@@ -191,14 +191,15 @@ func (h *CloudflareHandler) SaveAppSettings(w http.ResponseWriter, r *http.Reque
|
||||
|
||||
func (h *CloudflareHandler) TestToken(w http.ResponseWriter, r *http.Request) {
|
||||
var request struct {
|
||||
Token string `json:"token"`
|
||||
Kind string `json:"kind"`
|
||||
AccountID string `json:"account_id"`
|
||||
Token string `json:"token"`
|
||||
Kind string `json:"kind"`
|
||||
}
|
||||
if err := json.NewDecoder(http.MaxBytesReader(w, r.Body, 1<<20)).Decode(&request); err != nil {
|
||||
writeError(r, w, http.StatusBadRequest, "请求格式无效")
|
||||
return
|
||||
}
|
||||
message, err := h.svc.TestToken(r.Context(), request.Token, request.Kind)
|
||||
message, err := h.svc.TestToken(r.Context(), request.AccountID, request.Token, request.Kind)
|
||||
if err != nil {
|
||||
writeError(r, w, http.StatusBadGateway, err.Error())
|
||||
return
|
||||
|
||||
@@ -297,12 +297,16 @@ func (s *Service) cloudflareAPI(ctx context.Context) (*CloudflareAPI, error) {
|
||||
}
|
||||
|
||||
// VerifyAPIToken 用 Account ID + API Token 调用 Cloudflare 账号级 tokens/verify 接口。
|
||||
func (s *Service) VerifyAPIToken(ctx context.Context, input string) (string, error) {
|
||||
// accountID / input 为空时回退到应用配置中已保存的值。
|
||||
func (s *Service) VerifyAPIToken(ctx context.Context, accountID, input string) (string, error) {
|
||||
row, err := s.store.GetSettingsRaw(ctx)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
accountID := strings.TrimSpace(row.AccountID)
|
||||
accountID = strings.TrimSpace(accountID)
|
||||
if accountID == "" {
|
||||
accountID = strings.TrimSpace(row.AccountID)
|
||||
}
|
||||
if accountID == "" {
|
||||
return "", fmt.Errorf("请先填写 Account ID")
|
||||
}
|
||||
@@ -320,8 +324,8 @@ func (s *Service) VerifyAPIToken(ctx context.Context, input string) (string, err
|
||||
}
|
||||
|
||||
// TestToken 验证 Account ID + API Token 是否可用。
|
||||
func (s *Service) TestToken(ctx context.Context, input, _ string) (string, error) {
|
||||
return s.VerifyAPIToken(ctx, input)
|
||||
func (s *Service) TestToken(ctx context.Context, accountID, input, _ string) (string, error) {
|
||||
return s.VerifyAPIToken(ctx, accountID, input)
|
||||
}
|
||||
|
||||
// attachConfig 从 config.yml 回填域名与回源 service,供编辑弹窗使用。
|
||||
|
||||
Reference in New Issue
Block a user