From 34be2cc964cb9f284700b48b2e4c3a00438dc91f Mon Sep 17 00:00:00 2001 From: Kleissner Date: Fri, 14 Oct 2022 16:28:43 +0200 Subject: [PATCH] webapi: /explore optional &offset= parameter which does not make sense to be used --- webapi/Search.go | 5 +++-- webapi/Shared Recent.go | 11 ++++++++--- webapi/readme.md | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/webapi/Search.go b/webapi/Search.go index 0e61360..1b7c7b5 100644 --- a/webapi/Search.go +++ b/webapi/Search.go @@ -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{} diff --git a/webapi/Shared Recent.go b/webapi/Shared Recent.go index a4055db..73cb9f7 100644 --- a/webapi/Shared Recent.go +++ b/webapi/Shared Recent.go @@ -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 { diff --git a/webapi/readme.md b/webapi/readme.md index 2c9970b..68c1427 100644 --- a/webapi/readme.md +++ b/webapi/readme.md @@ -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. ```