webapi: /explore optional &offset= parameter which does not make sense to be used

This commit is contained in:
Kleissner
2022-10-14 16:28:43 +02:00
parent 0e3e8dc988
commit 34be2cc964
3 changed files with 12 additions and 6 deletions

View File

@@ -349,11 +349,12 @@ 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]
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) {
r.ParseForm()
offset, _ := strconv.Atoi(r.Form.Get("offset"))
limit, err := strconv.Atoi(r.Form.Get("limit"))
if err != nil {
limit = 100
@@ -363,7 +364,7 @@ func (api *WebapiInstance) apiExplore(w http.ResponseWriter, r *http.Request) {
fileType = -1
}
resultFiles := api.queryRecentShared(api.backend, fileType, uint64(limit*20/100), uint64(limit))
resultFiles := api.queryRecentShared(api.backend, fileType, uint64(limit*20/100), uint64(offset), uint64(limit))
var result SearchResult
result.Files = []apiFile{}

View File

@@ -13,7 +13,7 @@ import (
)
// queryRecentShared returns recently shared files on the network from random peers until the limit is reached.
func (api *WebapiInstance) queryRecentShared(backend *core.Backend, fileType int, limitPeer, limitTotal uint64) (files []blockchain.BlockRecordFile) {
func (api *WebapiInstance) queryRecentShared(backend *core.Backend, fileType int, limitPeer, offsetTotal, limitTotal uint64) (files []blockchain.BlockRecordFile) {
if limitPeer == 0 {
limitPeer = 1
}
@@ -50,13 +50,18 @@ func (api *WebapiInstance) queryRecentShared(backend *core.Backend, fileType int
// found a new file! append.
if filesFromPeer < limitPeer {
filesFromPeer++
if offsetTotal > 0 {
offsetTotal--
continue
}
files = append(files, file)
if uint64(len(files)) >= limitTotal {
return
}
filesFromPeer++
} else if uint64(len(filesSeconday)) < limitTotal-uint64(len(files)) {
filesSeconday = append(filesSeconday, file)
} else {

View File

@@ -920,7 +920,7 @@ Result: 200 with JSON structure apiResponseDownloadStatus (using APIStatus a
This returns recently shared files in Peernet. Results are returned in real-time. The file type is an optional filter.
```
Request: GET /explore?limit=[max records]&type=[file type]
Request: GET /explore?limit=[max records]&type=[file type]&offset=[offset]
Result: 200 with JSON structure SearchResult. Check the field status.
```