diff --git a/webapi/Merge directory.go b/webapi/Merge directory.go index 86faec4..a92535f 100644 --- a/webapi/Merge directory.go +++ b/webapi/Merge directory.go @@ -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 diff --git a/webapi/Search Dispatch.go b/webapi/Search Dispatch.go index 76d473f..a7787a9 100644 --- a/webapi/Search Dispatch.go +++ b/webapi/Search Dispatch.go @@ -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 diff --git a/webapi/Search Job.go b/webapi/Search Job.go index 4dfd091..3d65c1c 100644 --- a/webapi/Search Job.go +++ b/webapi/Search Job.go @@ -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 diff --git a/webapi/Search.go b/webapi/Search.go index 8d8c1aa..d6401f6 100644 --- a/webapi/Search.go +++ b/webapi/Search.go @@ -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) diff --git a/webapi/readme.md b/webapi/readme.md index 62af342..c2d0554 100644 --- a/webapi/readme.md +++ b/webapi/readme.md @@ -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 {