mirror of
https://github.com/PeernetOfficial/core.git
synced 2026-07-17 10:57:49 +01:00
added filter to search based on NodeID
This commit is contained in:
@@ -36,6 +36,7 @@ type SearchRequest struct {
|
||||
FileFormat int `json:"fileformat"` // File format such as PDF, Word, Ebook, etc. See core.FormatX. -1 = not used.
|
||||
SizeMin int `json:"sizemin"` // Min file size in bytes. -1 = not used.
|
||||
SizeMax int `json:"sizemax"` // Max file size in bytes. -1 = not used.
|
||||
NodeID string `json:"node"` // Filter based on the NodeID provided
|
||||
}
|
||||
|
||||
// Sort orders
|
||||
@@ -156,8 +157,9 @@ func (api *WebapiInstance) apiSearchResult(w http.ResponseWriter, r *http.Reques
|
||||
sort, _ := strconv.Atoi(r.Form.Get("sort"))
|
||||
sizeMin, _ := strconv.Atoi(r.Form.Get("sizemin"))
|
||||
sizeMax, _ := strconv.Atoi(r.Form.Get("sizemax"))
|
||||
nodeID, _ := DecodeBlake3Hash(r.Form.Get("node"))
|
||||
|
||||
filter := inputToSearchFilter(sort, fileType, fileFormat, dateFrom, dateTo, sizeMin, sizeMax)
|
||||
filter := inputToSearchFilter(sort, fileType, fileFormat, dateFrom, dateTo, sizeMin, sizeMax, nodeID)
|
||||
|
||||
job.RuntimeFilter(filter)
|
||||
}
|
||||
@@ -418,15 +420,17 @@ func (input *SearchRequest) Parse() (Timeout time.Duration) {
|
||||
|
||||
// ToSearchFilter converts the user input to a valid search filter
|
||||
func (input *SearchRequest) ToSearchFilter() (output SearchFilter) {
|
||||
return inputToSearchFilter(input.Sort, input.FileType, input.FileFormat, input.DateFrom, input.DateTo, input.SizeMin, input.SizeMax)
|
||||
hash, _ := DecodeBlake3Hash(input.NodeID)
|
||||
return inputToSearchFilter(input.Sort, input.FileType, input.FileFormat, input.DateFrom, input.DateTo, input.SizeMin, input.SizeMax, hash)
|
||||
}
|
||||
|
||||
func inputToSearchFilter(Sort, FileType, FileFormat int, DateFrom, DateTo string, SizeMin, SizeMax int) (output SearchFilter) {
|
||||
func inputToSearchFilter(Sort, FileType, FileFormat int, DateFrom, DateTo string, SizeMin, SizeMax int, NodeID []byte) (output SearchFilter) {
|
||||
output.Sort = Sort
|
||||
output.FileType = FileType
|
||||
output.FileFormat = FileFormat
|
||||
output.SizeMin = SizeMin
|
||||
output.SizeMax = SizeMax
|
||||
output.NodeID = NodeID
|
||||
|
||||
dateFrom, errFrom := time.Parse(apiDateFormat, DateFrom)
|
||||
dateTo, errTo := time.Parse(apiDateFormat, DateTo)
|
||||
|
||||
Reference in New Issue
Block a user