From 0dd57431872e620ab2d0c0854fd745c3e660b587 Mon Sep 17 00:00:00 2001 From: kris-dev-hub Date: Tue, 26 Dec 2023 16:38:17 +0100 Subject: [PATCH] fix: code cleaning --- pkg/linkdb/controller.go | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/pkg/linkdb/controller.go b/pkg/linkdb/controller.go index 72cfd85..4446828 100644 --- a/pkg/linkdb/controller.go +++ b/pkg/linkdb/controller.go @@ -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 @@ -129,31 +134,31 @@ 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"}} } @@ -161,21 +166,6 @@ func generateFilter(domain string, domainParsed string, apiRequest *APIRequest) } } - /* - // 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 }