Search: Add separator.

webapi: Search results and explore: set tag TagSharedByCount if file owner is active peer.
This commit is contained in:
Kleissner
2021-12-14 02:13:04 +01:00
parent 281622aa49
commit e41e6820bc
3 changed files with 12 additions and 5 deletions

View File

@@ -21,7 +21,7 @@ func text2Hashes(text string, hashes map[[32]byte]string) {
if unicode.IsSpace(char) {
return true
}
return strings.ContainsAny(string(char), "+-._()[],")
return strings.ContainsAny(string(char), "+-._()[],")
})
for _, word := range words {

View File

@@ -10,6 +10,7 @@ import (
"time"
"github.com/PeernetOfficial/core"
"github.com/PeernetOfficial/core/blockchain"
)
func (api *WebapiInstance) dispatchSearch(input SearchRequest) (job *SearchJob) {
@@ -44,16 +45,20 @@ resultLoop:
continue
}
// new result
newFile := blockRecordFileToAPI(file)
// Deduplicate based on file hash from the same peer.
for n := range job.AllFiles {
if bytes.Equal(job.AllFiles[n].Hash, newFile.Hash) && bytes.Equal(job.AllFiles[n].NodeID, newFile.NodeID) {
if bytes.Equal(job.AllFiles[n].Hash, file.Hash) && bytes.Equal(job.AllFiles[n].NodeID, file.NodeID) {
continue resultLoop
}
}
if peer := core.NodelistLookup(file.NodeID); peer != nil {
file.Tags = append(file.Tags, blockchain.TagFromNumber(blockchain.TagSharedByCount, 1))
}
// new result
newFile := blockRecordFileToAPI(file)
job.Files = append(job.Files, &newFile)
job.AllFiles = append(job.AllFiles, &newFile)
job.requireSort = true

View File

@@ -39,6 +39,8 @@ func queryRecentShared(backend *core.Backend, fileType int, limitPeer, limitTota
for _, record := range blockDecoded.RecordsDecoded {
if file, ok := record.(blockchain.BlockRecordFile); ok && isFileTypeMatchBlock(&file, fileType) {
file.Tags = append(file.Tags, blockchain.TagFromNumber(blockchain.TagSharedByCount, 1))
// found a new file! append.
if filesFromPeer < limitPeer {
files = append(files, file)