From 1766aa85cb243dc777ced1ca2faa5ab9c2928a11 Mon Sep 17 00:00:00 2001 From: Akilan Selvacoumar <31743758+Akilan1999@users.noreply.github.com> Date: Sun, 12 Feb 2023 10:06:17 +0000 Subject: [PATCH] made backend varaible public (#104) --- webapi/API.go | 8 ++++---- webapi/Search.go | 18 +++++++++--------- webapi/Shared Recent.go | 4 ++-- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/webapi/API.go b/webapi/API.go index ca215fc..61e183f 100644 --- a/webapi/API.go +++ b/webapi/API.go @@ -22,7 +22,7 @@ import ( ) type WebapiInstance struct { - backend *core.Backend + Backend *core.Backend geoipCityReader *geoip2.CityReader // Router can be used to register additional API functions @@ -57,7 +57,7 @@ func Start(Backend *core.Backend, ListenAddresses []string, UseSSL bool, Certifi } api = &WebapiInstance{ - backend: Backend, + Backend: Backend, Router: mux.NewRouter(), AllowKeyInParam: []string{"/file/read", "/file/view"}, allJobs: make(map[uuid.UUID]*SearchJob), @@ -170,7 +170,7 @@ func DecodeJSON(w http.ResponseWriter, r *http.Request, data interface{}) (err e // authenticateMiddleware returns a middleware function to be used with mux.Router.Use(). It handles all authentication functionality. func (api *WebapiInstance) authenticateMiddleware(APIKey uuid.UUID) func(http.Handler) http.Handler { - return (func(next http.Handler) http.Handler { + return func(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { keyID, err := uuid.Parse(r.Header.Get("x-api-key")) if err != nil { // special case for some paths @@ -194,5 +194,5 @@ func (api *WebapiInstance) authenticateMiddleware(APIKey uuid.UUID) func(http.Ha next.ServeHTTP(w, r) }) - }) + } } diff --git a/webapi/Search.go b/webapi/Search.go index 9e16860..c486fa9 100644 --- a/webapi/Search.go +++ b/webapi/Search.go @@ -106,7 +106,7 @@ func (api *WebapiInstance) apiSearch(w http.ResponseWriter, r *http.Request) { job := api.dispatchSearch(input) - EncodeJSON(api.backend, w, r, SearchRequestResponse{Status: 0, ID: job.id}) + EncodeJSON(api.Backend, w, r, SearchRequestResponse{Status: 0, ID: job.id}) } /* @@ -143,7 +143,7 @@ func (api *WebapiInstance) apiSearchResult(w http.ResponseWriter, r *http.Reques // find the job ID job := api.JobLookup(jobID) if job == nil { - EncodeJSON(api.backend, w, r, SearchResult{Status: 2}) + EncodeJSON(api.Backend, w, r, SearchResult{Status: 2}) return } @@ -203,7 +203,7 @@ func (api *WebapiInstance) apiSearchResult(w http.ResponseWriter, r *http.Reques result.Statistic = job.Statistics() } - EncodeJSON(api.backend, w, r, result) + EncodeJSON(api.Backend, w, r, result) } /* @@ -227,7 +227,7 @@ func (api *WebapiInstance) apiSearchResultStream(w http.ResponseWriter, r *http. // look up the job job := api.JobLookup(jobID) if job == nil { - EncodeJSON(api.backend, w, r, SearchResult{Status: 2}) + EncodeJSON(api.Backend, w, r, SearchResult{Status: 2}) return } @@ -340,13 +340,13 @@ func (api *WebapiInstance) apiSearchStatistic(w http.ResponseWriter, r *http.Req // find the job ID job := api.JobLookup(jobID) if job == nil { - EncodeJSON(api.backend, w, r, SearchStatistic{Status: 2}) + EncodeJSON(api.Backend, w, r, SearchStatistic{Status: 2}) return } stats := job.Statistics() - EncodeJSON(api.backend, w, r, SearchStatistic{SearchStatisticData: stats, Status: 0, IsTerminated: job.IsTerminated()}) + EncodeJSON(api.Backend, w, r, SearchStatistic{SearchStatisticData: stats, Status: 0, IsTerminated: job.IsTerminated()}) } /* @@ -371,7 +371,7 @@ func (api *WebapiInstance) apiExplore(w http.ResponseWriter, r *http.Request) { result := api.ExploreHelper(fileType, limit, offset, []byte{}, false) - EncodeJSON(api.backend, w, r, result) + EncodeJSON(api.Backend, w, r, result) } /* @@ -398,12 +398,12 @@ func (api *WebapiInstance) apiExploreNodeID(w http.ResponseWriter, r *http.Reque result := api.ExploreHelper(fileType, limit, offset, NodeId, true) - EncodeJSON(api.backend, w, r, result) + 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) + resultFiles := api.queryRecentShared(api.Backend, fileType, uint64(limit*20/100), uint64(offset), uint64(limit), nodeID, nodeIDState) var result SearchResult result.Files = []apiFile{} diff --git a/webapi/Shared Recent.go b/webapi/Shared Recent.go index 32487d9..d7d6eb5 100644 --- a/webapi/Shared Recent.go +++ b/webapi/Shared Recent.go @@ -25,10 +25,10 @@ func (api *WebapiInstance) queryRecentShared(backend *core.Backend, fileType int // check if the NodeID is provided or not if len(nodeID) == 0 && !nodeIDState { // Use the peer list to know about active peers. Random order! - peerList = api.backend.PeerlistGet() + peerList = api.Backend.PeerlistGet() } else { // Get peer information based on the NodeID provided - _, peer, err := api.backend.FindNode(nodeID, time.Second*5) + _, peer, err := api.Backend.FindNode(nodeID, time.Second*5) if err != nil { return }