Skip to content

Commit

Permalink
fix: code cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
kris-dev-hub committed Dec 26, 2023
1 parent 1518938 commit 0dd5743
Showing 1 changed file with 13 additions and 23 deletions.
36 changes: 13 additions & 23 deletions pkg/linkdb/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ import (
"golang.org/x/net/publicsuffix"
)

const (
FilterKindExact = "exact"
FilterKindAny = "any"
)

func (app *App) ControllerGetDomainLinks(apiRequest APIRequest) ([]LinkOut, error) {
var links []LinkRow
var outLinks []LinkOut
Expand Down Expand Up @@ -129,53 +134,38 @@ func generateFilter(domain string, domainParsed string, apiRequest *APIRequest)
filter["nofollow"] = val
}
case "Link Path":
if filterData.Kind == "exact" {
if filterData.Kind == FilterKindExact {
filter["linkpath"] = bson.M{"$regex": primitive.Regex{Pattern: "^" + filterData.Val + "$", Options: "i"}}
}
if filterData.Kind == "any" {
if filterData.Kind == FilterKindAny {
filter["linkpath"] = bson.M{"$regex": primitive.Regex{Pattern: filterData.Val, Options: "i"}}
}
case "Source Host":
if filterData.Kind == "exact" {
if filterData.Kind == FilterKindExact {
filter["pagehost"] = bson.M{"$regex": primitive.Regex{Pattern: "^" + filterData.Val + "$", Options: "i"}}
}
if filterData.Kind == "any" {
if filterData.Kind == FilterKindAny {
filter["pagehost"] = bson.M{"$regex": primitive.Regex{Pattern: filterData.Val, Options: "i"}}
}
case "Source Path":
if filterData.Kind == "exact" {
if filterData.Kind == FilterKindExact {
filter["pagepath"] = bson.M{"$regex": primitive.Regex{Pattern: "^" + filterData.Val + "$", Options: "i"}}
}
if filterData.Kind == "any" {
if filterData.Kind == FilterKindAny {
filter["pagepath"] = bson.M{"$regex": primitive.Regex{Pattern: filterData.Val, Options: "i"}}
}
case "Anchor":
if filterData.Kind == "exact" {
if filterData.Kind == FilterKindExact {
filter["linktext"] = bson.M{"$regex": primitive.Regex{Pattern: "^" + filterData.Val + "$", Options: "i"}}
}
if filterData.Kind == "any" {
if filterData.Kind == FilterKindAny {
filter["linktext"] = bson.M{"$regex": primitive.Regex{Pattern: filterData.Val, Options: "i"}}
}

}
}
}

/*
// Create filter by no follow
if apiRequest.NoFollow != nil {
filter["nofollow"] = *apiRequest.NoFollow
}
// Create filter by text exact
if apiRequest.TextExact != nil {
filter["linktext"] = bson.M{"$regex": primitive.Regex{Pattern: "^" + *apiRequest.TextExact + "$", Options: "i"}}
}
// Create filter by text any
if apiRequest.TextAny != nil {
filter["linktext"] = bson.M{"$regex": primitive.Regex{Pattern: *apiRequest.TextAny, Options: "i"}}
}
*/
return filter
}

Expand Down

0 comments on commit 0dd5743

Please sign in to comment.