made backend varaible public (#104)

This commit is contained in:
Akilan Selvacoumar
2023-02-12 10:06:17 +00:00
committed by GitHub
parent 9775525d35
commit 1766aa85cb
3 changed files with 15 additions and 15 deletions

View File

@@ -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)
})
})
}
}

View File

@@ -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{}

View File

@@ -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
}