Change directory route and document change (#107)

* changed route to view files added by a certain node

* gofmt my changes

* added fix for blockchain/explore to also accept localnodes as a parameter.

* added local blockchain search
This commit is contained in:
Akilan Selvacoumar
2023-03-10 09:47:18 +00:00
committed by GitHub
parent 2b2f20ca18
commit b34b2e2b7c
2 changed files with 63 additions and 27 deletions

View File

@@ -7,9 +7,10 @@ Author: Peter Kleissner
package webapi
import (
"encoding/hex"
"net/http"
"strconv"
"bytes"
"encoding/hex"
"net/http"
"strconv"
"github.com/PeernetOfficial/core/blockchain"
)
@@ -147,3 +148,38 @@ func (api *WebapiInstance) apiExploreNodeID(w http.ResponseWriter, r *http.Reque
EncodeJSON(api.Backend, w, r, result)
}
/*
apiExploreNodeID returns the shared files of a particular node in Peernet. Results are returned in real-time. The file type is an optional filter. See TypeX.
Special type -2 = Binary, Compressed, Container, Executable. This special type includes everything except Documents, Video, Audio, Ebooks, Picture, Text.
Request: GET /blockchain/view?limit=[max records]&type=[file type]&offset=[offset]&node=[node id]
Result: 200 with JSON structure SearchResult. Check the field status.
*/
func (api *WebapiInstance) apiExploreNodeID(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
offset, _ := strconv.Atoi(r.Form.Get("offset"))
limit, err := strconv.Atoi(r.Form.Get("limit"))
if err != nil {
limit = 100
}
// ID fields for results for a specific node ID.
NodeId, _ := DecodeBlake3Hash(r.Form.Get("node"))
fileType, err := strconv.Atoi(r.Form.Get("type"))
if err != nil {
fileType = -1
}
// check if the node IDs are the same
if bytes.Compare(NodeId, api.Backend.SelfNodeID()) == 0 {
// setting the value of block to 0
r.Form.Add("block", "0")
api.apiBlockchainRead(w, r)
return
}
result := api.ExploreHelper(fileType, limit, offset, NodeId, true)
EncodeJSON(api.Backend, w, r, result)
}