Skip to content

Commit

Permalink
feat: added more filters, frontend send kind=exact when original mess…
Browse files Browse the repository at this point in the history
…age is in ", and any in other cases
  • Loading branch information
kris-dev-hub committed Dec 26, 2023
1 parent 5461a79 commit 1518938
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion pkg/linkdb/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"strconv"
"time"

"go.mongodb.org/mongo-driver/bson/primitive"

"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo/options"
"golang.org/x/net/publicsuffix"
Expand Down Expand Up @@ -121,11 +123,40 @@ func generateFilter(domain string, domainParsed string, apiRequest *APIRequest)
if apiRequest.Filters != nil {
for _, filterData := range *apiRequest.Filters {
switch filterData.Name {
case "NoFollow":
case "No Follow":
val, err := strconv.Atoi(filterData.Val)
if err == nil {
filter["nofollow"] = val
}
case "Link Path":
if filterData.Kind == "exact" {

Check failure on line 132 in pkg/linkdb/controller.go

View workflow job for this annotation

GitHub Actions / lint

string `exact` has 4 occurrences, make it a constant (goconst)
filter["linkpath"] = bson.M{"$regex": primitive.Regex{Pattern: "^" + filterData.Val + "$", Options: "i"}}
}
if filterData.Kind == "any" {

Check failure on line 135 in pkg/linkdb/controller.go

View workflow job for this annotation

GitHub Actions / lint

string `any` has 4 occurrences, make it a constant (goconst)
filter["linkpath"] = bson.M{"$regex": primitive.Regex{Pattern: filterData.Val, Options: "i"}}
}
case "Source Host":
if filterData.Kind == "exact" {
filter["pagehost"] = bson.M{"$regex": primitive.Regex{Pattern: "^" + filterData.Val + "$", Options: "i"}}
}
if filterData.Kind == "any" {
filter["pagehost"] = bson.M{"$regex": primitive.Regex{Pattern: filterData.Val, Options: "i"}}
}
case "Source Path":
if filterData.Kind == "exact" {
filter["pagepath"] = bson.M{"$regex": primitive.Regex{Pattern: "^" + filterData.Val + "$", Options: "i"}}
}
if filterData.Kind == "any" {
filter["pagepath"] = bson.M{"$regex": primitive.Regex{Pattern: filterData.Val, Options: "i"}}
}
case "Anchor":
if filterData.Kind == "exact" {
filter["linktext"] = bson.M{"$regex": primitive.Regex{Pattern: "^" + filterData.Val + "$", Options: "i"}}
}
if filterData.Kind == "any" {
filter["linktext"] = bson.M{"$regex": primitive.Regex{Pattern: filterData.Val, Options: "i"}}
}

}
}
}
Expand Down

0 comments on commit 1518938

Please sign in to comment.