diff --git a/internal/provider/providers/dondominio/create.go b/internal/provider/providers/dondominio/create.go new file mode 100644 index 000000000..f789789cf --- /dev/null +++ b/internal/provider/providers/dondominio/create.go @@ -0,0 +1,39 @@ +package dondominio + +import ( + "context" + "net/http" + "net/netip" + + "github.com/qdm12/ddns-updater/internal/provider/constants" +) + +// See https://dondominio.dev/en/api/docs/api/#dns-zone-create-service-dnscreate +func (p *Provider) create(ctx context.Context, client *http.Client, ip netip.Addr) (err error) { + recordType := constants.A + if ip.Is6() { + recordType = constants.AAAA + } + requestData := struct { + APIUser string `json:"apiuser"` + APIPasswd string `json:"apipasswd"` + ServiceName string `json:"serviceName"` + Name string `json:"name"` // Name for the DNS zone + Type string `json:"type"` + Value string `json:"value"` + }{ + APIUser: p.username, + APIPasswd: p.password, + ServiceName: p.name, + Name: p.BuildDomainName(), + Type: recordType, + Value: ip.String(), + } + + _, err = apiCall(ctx, client, "/service/dnscreate", requestData) + if err != nil { + return err + } + + return nil +} diff --git a/internal/provider/providers/dondominio/provider.go b/internal/provider/providers/dondominio/provider.go index 9b6ccfd51..329a6614e 100644 --- a/internal/provider/providers/dondominio/provider.go +++ b/internal/provider/providers/dondominio/provider.go @@ -112,6 +112,15 @@ func (p *Provider) Update(ctx context.Context, client *http.Client, ip netip.Add ids = aaaaIDs } + if len(ids) == 0 { + err = p.create(ctx, client, ip) + if err != nil { + return netip.Addr{}, fmt.Errorf("creating %s record for %s: %w", + recordType, p.BuildDomainName(), err) + } + return ip, nil + } + for _, id := range ids { err = p.update(ctx, client, id, ip) if err != nil {