mirror of
https://github.com/PeernetOfficial/core.git
synced 2026-07-20 03:47:50 +01:00
added possibility to get profile using NodeID
This commit is contained in:
@@ -31,11 +31,21 @@ type apiBlockRecordProfile struct {
|
||||
/*
|
||||
apiProfileList lists all users profile fields.
|
||||
|
||||
Request: GET /profile/list
|
||||
Request: GET /profile/list?node[nodeid]
|
||||
Response: 200 with JSON structure apiProfileData
|
||||
*/
|
||||
func (api *WebapiInstance) apiProfileList(w http.ResponseWriter, r *http.Request) {
|
||||
fields, status := api.Backend.UserBlockchain.ProfileList()
|
||||
|
||||
NodeID, valid := DecodeBlake3Hash(r.Form.Get("node"))
|
||||
|
||||
var fields []blockchain.BlockRecordProfile
|
||||
var status int
|
||||
|
||||
if valid {
|
||||
fields, status = api.Backend.NodelistLookup(NodeID).Backend.UserBlockchain.ProfileList()
|
||||
} else {
|
||||
fields, status = api.Backend.UserBlockchain.ProfileList()
|
||||
}
|
||||
|
||||
result := apiProfileData{Status: status}
|
||||
for n := range fields {
|
||||
@@ -48,12 +58,13 @@ func (api *WebapiInstance) apiProfileList(w http.ResponseWriter, r *http.Request
|
||||
/*
|
||||
apiProfileRead reads a specific users profile field. See core.ProfileX for recognized fields.
|
||||
|
||||
Request: GET /profile/read?field=[index]
|
||||
Request: GET /profile/read?field=[index]&node=[nodeid]
|
||||
Response: 200 with JSON structure apiProfileData
|
||||
*/
|
||||
func (api *WebapiInstance) apiProfileRead(w http.ResponseWriter, r *http.Request) {
|
||||
r.ParseForm()
|
||||
fieldN, err1 := strconv.Atoi(r.Form.Get("field"))
|
||||
NodeID, valid := DecodeBlake3Hash(r.Form.Get("node"))
|
||||
|
||||
if err1 != nil || fieldN < 0 {
|
||||
http.Error(w, "", http.StatusBadRequest)
|
||||
@@ -61,10 +72,18 @@ func (api *WebapiInstance) apiProfileRead(w http.ResponseWriter, r *http.Request
|
||||
}
|
||||
|
||||
var result apiProfileData
|
||||
|
||||
var data []byte
|
||||
if data, result.Status = api.Backend.UserBlockchain.ProfileReadField(uint16(fieldN)); result.Status == blockchain.StatusOK {
|
||||
result.Fields = append(result.Fields, blockRecordProfileToAPI(blockchain.BlockRecordProfile{Type: uint16(fieldN), Data: data}))
|
||||
|
||||
if !valid {
|
||||
if data, result.Status = api.Backend.UserBlockchain.ProfileReadField(uint16(fieldN)); result.Status == blockchain.StatusOK {
|
||||
result.Fields = append(result.Fields, blockRecordProfileToAPI(blockchain.BlockRecordProfile{Type: uint16(fieldN), Data: data}))
|
||||
}
|
||||
} else {
|
||||
if api.Backend.NodelistLookup(NodeID) != nil {
|
||||
if data, result.Status = api.Backend.NodelistLookup(NodeID).Backend.UserBlockchain.ProfileReadField(uint16(fieldN)); result.Status == blockchain.StatusOK {
|
||||
result.Fields = append(result.Fields, blockRecordProfileToAPI(blockchain.BlockRecordProfile{Type: uint16(fieldN), Data: data}))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EncodeJSON(api.Backend, w, r, result)
|
||||
|
||||
@@ -44,31 +44,31 @@ func (api *WebapiInstance) queryRecentShared(backend *core.Backend, fileType int
|
||||
|
||||
var filesFromPeer uint64
|
||||
|
||||
var ProfileImage []byte
|
||||
var Name string
|
||||
//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
|
||||
}
|
||||
}
|
||||
}
|
||||
//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:
|
||||
@@ -88,11 +88,6 @@ 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++
|
||||
|
||||
@@ -496,7 +496,7 @@ Below is the list of well known profile information. Clients may define addition
|
||||
This lists all profile fields.
|
||||
|
||||
```
|
||||
Request: GET /profile/list
|
||||
Request: GET /profile/list&node=[node id<optional>]
|
||||
Response: 200 with JSON structure apiProfileData
|
||||
```
|
||||
|
||||
@@ -538,7 +538,7 @@ Example response:
|
||||
This reads a specific profile field. See ProfileX for recognized fields.
|
||||
|
||||
```
|
||||
Request: GET /profile/read?field=[index]
|
||||
Request: GET /profile/read?field=[index]&node=[node id<optional>]
|
||||
Response: 200 with JSON structure apiProfileData
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user