Skip to content

Commit

Permalink
feat(cloudflare): support comment param (#980)
Browse files Browse the repository at this point in the history
* feat(cloudflare): support `comment` param

* style: apply suggestion

Co-authored-by: WaterLemons2k <[email protected]>

* style: Apply suggestions from code review

Co-authored-by: WaterLemons2k <[email protected]>

---------

Co-authored-by: WaterLemons2k <[email protected]>
  • Loading branch information
ngc7331 and WaterLemons2k authored Jan 14, 2024
1 parent 20f1b29 commit fe9f437
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion dns/cloudflare.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type CloudflareRecord struct {
Content string `json:"content"`
Proxied bool `json:"proxied"`
TTL int `json:"ttl"`
Comment string `json:"comment"`
}

// CloudflareStatus 公共状态
Expand Down Expand Up @@ -105,13 +106,19 @@ func (cf *Cloudflare) addUpdateDomainRecords(recordType string) {
return
}

// 存在参数才进行筛选
comment := domain.GetCustomParams().Get("comment")
if comment != "" {
comment = fmt.Sprintf("&comment=%s", comment)
}

zoneID := result.Result[0].ID

var records CloudflareRecordsResp
// getDomains 最多更新前50条
err = cf.request(
"GET",
fmt.Sprintf(zonesAPI+"/%s/dns_records?type=%s&name=%s&per_page=50", zoneID, recordType, domain),
fmt.Sprintf(zonesAPI+"/%s/dns_records?type=%s&name=%s&per_page=50%s", zoneID, recordType, domain, comment),
nil,
&records,
)
Expand Down Expand Up @@ -146,6 +153,7 @@ func (cf *Cloudflare) create(zoneID string, domain *config.Domain, recordType st
Content: ipAddr,
Proxied: false,
TTL: cf.TTL,
Comment: domain.GetCustomParams().Get("comment"),
}
record.Proxied = domain.GetCustomParams().Get("proxied") == "true"
var status CloudflareStatus
Expand Down

0 comments on commit fe9f437

Please sign in to comment.