mirror of
https://github.com/PeernetOfficial/core.git
synced 2026-07-17 02:47:51 +01:00
added filter to search based on NodeID
This commit is contained in:
@@ -98,6 +98,26 @@ func (api *WebapiInstance) GreedySearchMergeDirection(nodeID *[][]byte, fileType
|
||||
|
||||
var filesFromPeer uint64
|
||||
|
||||
//var Name string
|
||||
//
|
||||
//ProfileNameFound := false
|
||||
//
|
||||
//// First iteration of the entire blockchain to search for the profile
|
||||
//// image and Username of the user
|
||||
//for blockN1 := peer.BlockchainHeight - 1; blockN1 > 0; blockN1-- {
|
||||
// blockDecoded, _, found, _ := api.Backend.ReadBlock(peer.PublicKey, peer.BlockchainVersion, blockN1)
|
||||
// if !found {
|
||||
// continue
|
||||
// }
|
||||
// // Adding profile image and Username to the output
|
||||
// for raw := range blockDecoded.Block.RecordsRaw {
|
||||
// if blockDecoded.Block.RecordsRaw[raw].Type == blockchain.ProfileName && !ProfileNameFound {
|
||||
// Name = string(blockDecoded.Block.RecordsRaw[raw].Data[:])
|
||||
// ProfileNameFound = true
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
// decode blocks from top down
|
||||
for blockN := peer.BlockchainHeight - 1; blockN > 0; blockN-- {
|
||||
blockDecoded, _, found, _ := api.Backend.ReadBlock(peer.PublicKey, peer.BlockchainVersion, blockN)
|
||||
@@ -114,6 +134,8 @@ func (api *WebapiInstance) GreedySearchMergeDirection(nodeID *[][]byte, fileType
|
||||
file.Tags = append(file.Tags, blockchain.TagFromText(blockchain.TagSharedByGeoIP, sharedByGeoIP))
|
||||
}
|
||||
|
||||
//file.Username = Name
|
||||
|
||||
// if both the hashes match
|
||||
if bytes.Equal(file.Hash, hash) {
|
||||
// set the Tags needed for the filter parameter
|
||||
|
||||
@@ -9,6 +9,7 @@ package webapi
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"github.com/PeernetOfficial/core/protocol"
|
||||
"time"
|
||||
|
||||
"github.com/PeernetOfficial/core/blockchain"
|
||||
@@ -43,6 +44,12 @@ func (job *SearchJob) localSearch(api *WebapiInstance, term string) {
|
||||
|
||||
resultLoop:
|
||||
for _, result := range results {
|
||||
|
||||
// check if the NodeID filter is provided
|
||||
if job.filtersStart.NodeID != nil && !(bytes.Equal(job.filtersStart.NodeID, protocol.PublicKey2NodeID(result.PublicKey))) {
|
||||
continue
|
||||
}
|
||||
|
||||
file, _, found, err := api.Backend.ReadFile(result.PublicKey, result.BlockchainVersion, result.BlockNumber, result.FileID)
|
||||
if err != nil || !found {
|
||||
continue
|
||||
|
||||
@@ -25,6 +25,7 @@ type SearchFilter struct {
|
||||
Sort int // Sort order. See SortX.
|
||||
SizeMin int // Min file size in bytes. -1 = not used.
|
||||
SizeMax int // Max file size in bytes. -1 = not used.
|
||||
NodeID []byte // Filter based on a NodeID provided
|
||||
}
|
||||
|
||||
// SearchJob is a collection of search jobs
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -617,7 +617,7 @@ Filters and sort order may be applied when starting the search at `/search`, or
|
||||
These are the available sort options:
|
||||
|
||||
| Sort | Constant | Info |
|
||||
| ---- | --------------------- | ----------------------------------------------------------------------------------- |
|
||||
|------|-----------------------|-------------------------------------------------------------------------------------|
|
||||
| 0 | SortNone | No sorting. Results are returned as they come in. |
|
||||
| 1 | SortRelevanceAsc | Least relevant results first. |
|
||||
| 2 | SortRelevanceDec | Most relevant results first. |
|
||||
@@ -629,6 +629,8 @@ These are the available sort options:
|
||||
| 8 | SortSizeDesc | File size descending. Largest files first. |
|
||||
| 9 | SortSharedByCountAsc | Shared by count ascending. Files that are shared by the least count of peers first. |
|
||||
| 10 | SortSharedByCountDesc | Shared by count descending. Files that are shared by the most count of peers first. |
|
||||
| 11 | Node | Only provide files of a search term based on the NodeID provided |
|
||||
|
||||
|
||||
The following filters are supported:
|
||||
|
||||
@@ -658,6 +660,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
|
||||
}
|
||||
|
||||
type SearchRequestResponse struct {
|
||||
|
||||
Reference in New Issue
Block a user