Skip to content

Commit

Permalink
fix(server): send domains in the API function
Browse files Browse the repository at this point in the history
  • Loading branch information
g0rbe committed Oct 5, 2023
1 parent 7208c01 commit 3c1c5af
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 20 deletions.
26 changes: 7 additions & 19 deletions server/route/api/history/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"errors"
"fmt"
"net/http"
"strconv"
"time"

"github.com/elmasy-com/columbus/db"
"github.com/elmasy-com/columbus/fault"
"github.com/elmasy-com/columbus/server/common"
"github.com/gin-gonic/gin"
)

Expand All @@ -17,23 +17,6 @@ type History struct {
Records []db.Record
}

// Return the "days" query parameter.
// If not set, returns -1.
func getQueryDays(c *gin.Context) (int, error) {

// Parse days query param
daysStr, daysSet := c.GetQuery("days")
if !daysSet {
return -1, nil
}

if daysStr == "" {
return -2, fmt.Errorf("empty")
}

return strconv.Atoi(daysStr)
}

func GetApiHistory(c *gin.Context) {

var err error
Expand All @@ -42,7 +25,7 @@ func GetApiHistory(c *gin.Context) {
d := c.Param("domain")

// Parse days query param
days, err := getQueryDays(c)
days, err := common.ParseQueryDays(c)
if err != nil {
c.Error(fault.ErrInvalidDays)
c.JSON(http.StatusBadRequest, fault.ErrInvalidDays)
Expand Down Expand Up @@ -95,6 +78,11 @@ func GetApiHistory(c *gin.Context) {

for i := range doms {

// Send domains to db.UpdaterChan channel if not full to update the DNS records.
if len(db.UpdaterChan) < cap(db.UpdaterChan) {
db.UpdaterChan <- db.UpdateableDomain{Domain: doms[i].String(), Type: db.UpdateExistingDomain}
}

hs = append(hs, History{Domain: doms[i].String(), Records: doms[i].Records})
}

Expand Down
19 changes: 18 additions & 1 deletion server/route/api/lookup/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/elmasy-com/columbus/db"
"github.com/elmasy-com/columbus/fault"
"github.com/elmasy-com/columbus/server/common"
"github.com/elmasy-com/elnet/dns"
"github.com/gin-gonic/gin"
)

Expand All @@ -18,7 +19,7 @@ func GetApiLookup(c *gin.Context) {
var err error

// Parse domain param
d := c.Param("domain")
d := dns.Clean(c.Param("domain"))

// Parse days query param
days, err := common.ParseQueryDays(c)
Expand Down Expand Up @@ -76,6 +77,22 @@ func GetApiLookup(c *gin.Context) {
return
}

for i := range subs {

var dom string

if subs[i] == "" {
dom = d
} else {
dom = fmt.Sprintf("%s.%s", subs[i], d)
}

// Send domains to db.UpdaterChan channel if not full to update the DNS records.
if len(db.UpdaterChan) < cap(db.UpdaterChan) {
db.UpdaterChan <- db.UpdateableDomain{Domain: dom, Type: db.UpdateExistingDomain}
}
}

_, err = db.TopListInsert(d)
if err != nil {
c.Error(fmt.Errorf("failed to insert topList: %w", err))
Expand Down
5 changes: 5 additions & 0 deletions server/route/report/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ func getReportDataDomains(doms []db.Domain) []frontend.DomainsData {

for i := range doms {

// Send domains to db.UpdaterChan channel if not full to update the DNS records.
if len(db.UpdaterChan) < cap(db.UpdaterChan) {
db.UpdaterChan <- db.UpdateableDomain{Domain: doms[i].String(), Type: db.UpdateExistingDomain}
}

dd := frontend.DomainsData{
Domain: doms[i].String(),
}
Expand Down

0 comments on commit 3c1c5af

Please sign in to comment.