route /expore/node added

This commit is contained in:
2023-02-01 00:45:44 +00:00
parent fc09dff2b1
commit f7a4b71f09
3 changed files with 184 additions and 146 deletions

View File

@@ -349,7 +349,7 @@ func (api *WebapiInstance) apiSearchStatistic(w http.ResponseWriter, r *http.Req
apiExplore returns recently shared files 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 /explore?limit=[max records]&type=[file type]&offset=[offset]&nodeid=[node id]
Request: GET /explore?limit=[max records]&type=[file type]&offset=[offset]
Result: 200 with JSON structure SearchResult. Check the field status.
*/
func (api *WebapiInstance) apiExplore(w http.ResponseWriter, r *http.Request) {
@@ -359,15 +359,47 @@ func (api *WebapiInstance) apiExplore(w http.ResponseWriter, r *http.Request) {
if err != nil {
limit = 100
}
// ID fields for results for a specific node ID.
nodeid, _ := DecodeBlake3Hash(r.Form.Get("nodeid"))
fileType, err := strconv.Atoi(r.Form.Get("type"))
if err != nil {
fileType = -1
}
resultFiles := api.queryRecentShared(api.backend, fileType, uint64(limit*20/100), uint64(offset), uint64(limit), nodeid)
result := api.ExploreHelper(fileType,limit,offset,[]byte{},false)
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 /explore/node?limit=[max records]&type=[file type]&offset=[offset]&NodeID=[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("NodeID"))
fileType, err := strconv.Atoi(r.Form.Get("type"))
if err != nil {
fileType = -1
}
result := api.ExploreHelper(fileType,limit,offset,NodeId,true)
EncodeJSON(api.backend, w, r, result)
}
// ExploreHelper Helper function for the explore route with the possibility search based on a node ID
func (api *WebapiInstance) ExploreHelper(fileType int, limit, offset int, nodeID []byte, nodeIDState bool) *SearchResult{
resultFiles := api.queryRecentShared(api.backend, fileType, uint64(limit*20/100), uint64(offset), uint64(limit), nodeID, nodeIDState)
var result SearchResult
result.Files = []apiFile{}
@@ -383,7 +415,7 @@ func (api *WebapiInstance) apiExplore(w http.ResponseWriter, r *http.Request) {
result.Status = 1 // No more results to expect
EncodeJSON(api.backend, w, r, result)
return &result
}
func (input *SearchRequest) Parse() (Timeout time.Duration) {