Add users blockchain data to the search index and provide it in search results. Updated webapi search and download.

This commit is contained in:
Kleissner
2021-12-14 15:45:03 +01:00
parent da0a6357de
commit c053c617c2
6 changed files with 103 additions and 5 deletions

View File

@@ -9,14 +9,22 @@ Temporary download code to provide dummy results for testing. To be replaced!
package webapi
import (
"bytes"
"os"
"time"
"github.com/PeernetOfficial/core"
"github.com/PeernetOfficial/core/warehouse"
)
// Starts the download.
func (info *downloadInfo) Start() {
// current user?
if bytes.Equal(info.nodeID, core.SelfNodeID()) {
info.DownloadSelf()
return
}
for n := 0; n < 3 && info.peer == nil; n++ {
_, info.peer, _ = core.FindNode(info.nodeID, time.Second*5)
@@ -168,3 +176,28 @@ func (info *downloadInfo) storeDownloadData(data []byte, offset uint64) (status
return DownloadResponseSuccess
}
func (info *downloadInfo) DownloadSelf() {
// Check if the file is available in the local warehouse.
_, fileInfo, status, _ := core.UserWarehouse.FileExists(info.hash)
if status != warehouse.StatusOK {
info.status = DownloadCanceled
return
}
info.file.Size = uint64(fileInfo.Size())
info.status = DownloadActive
// read the file
status, bytesRead, _ := core.UserWarehouse.ReadFile(info.hash, 0, int64(fileInfo.Size()), info.DiskFile.Handle)
info.DiskFile.StoredSize = uint64(bytesRead)
if status != warehouse.StatusOK {
info.status = DownloadCanceled
return
}
info.Finish()
info.DeleteDefer(time.Hour * 1) // cache the details for 1 hour before removing}
}

View File

@@ -54,7 +54,10 @@ resultLoop:
}
}
if peer := core.NodelistLookup(file.NodeID); peer != nil {
if bytes.Equal(file.NodeID, core.SelfNodeID()) {
// Indicates data from the current user.
file.Tags = append(file.Tags, blockchain.TagFromNumber(blockchain.TagSharedByCount, 1))
} else if peer := core.NodelistLookup(file.NodeID); peer != nil {
// add the tags 'Shared By Count' and 'Shared By GeoIP'
file.Tags = append(file.Tags, blockchain.TagFromNumber(blockchain.TagSharedByCount, 1))
if latitude, longitude, valid := api.Peer2GeoIP(peer); valid {