huge changes that need more doucmenting

This commit is contained in:
2023-05-30 18:42:33 +01:00
parent 201a5441bb
commit d06a49eb28
88 changed files with 169 additions and 112 deletions

View File

@@ -1,5 +1,5 @@
/*
File Name: Shared Recent.go
File Username: Shared Recent.go
Copyright: 2021 Peernet Foundation s.r.o.
Author: Peter Kleissner
*/
@@ -18,7 +18,6 @@ func (api *WebapiInstance) queryRecentShared(backend *core.Backend, fileType int
if limitPeer == 0 {
limitPeer = 1
}
// Assign peer list as an empty array
var peerList []*core.PeerInfo
@@ -45,10 +44,37 @@ func (api *WebapiInstance) queryRecentShared(backend *core.Backend, fileType int
var filesFromPeer uint64
var ProfileImage []byte
var Name string
ProfileNameFound := false
ProfilePictureFound := 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, _ := 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.ProfilePicture && !ProfilePictureFound {
ProfileImage = blockDecoded.Block.RecordsRaw[raw].Data
ProfilePictureFound = true
}
if blockDecoded.Block.RecordsRaw[raw].Type == blockchain.ProfileName && !ProfileNameFound {
Name = string(blockDecoded.Block.RecordsRaw[raw].Data[:])
ProfileNameFound = true
}
}
}
// decode blocks from top down
blockLoop:
for blockN := peer.BlockchainHeight - 1; blockN > 0; blockN-- {
blockDecoded, _, found, _ := backend.ReadBlock(peer.PublicKey, peer.BlockchainVersion, blockN)
if !found {
continue
}
@@ -62,6 +88,11 @@ func (api *WebapiInstance) queryRecentShared(backend *core.Backend, fileType int
file.Tags = append(file.Tags, blockchain.TagFromText(blockchain.TagSharedByGeoIP, sharedByGeoIP))
}
// Add profile image
file.ProfileImage = ProfileImage
// Add profile name
file.Username = Name
// found a new file! append.
if filesFromPeer < limitPeer {
filesFromPeer++