Properly set remote user address
This commit is contained in:
@@ -17,11 +17,12 @@ var client = &http.Client{}
|
|||||||
type PixelAPI struct {
|
type PixelAPI struct {
|
||||||
apiEndpoint string
|
apiEndpoint string
|
||||||
apiKey string
|
apiKey string
|
||||||
|
RealIP string
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new Pixeldrain API client to query the Pixeldrain API with
|
// New creates a new Pixeldrain API client to query the Pixeldrain API with
|
||||||
func New(apiEndpoint, apiKey string) *PixelAPI {
|
func New(apiEndpoint, apiKey string) *PixelAPI {
|
||||||
return &PixelAPI{apiEndpoint, apiKey}
|
return &PixelAPI{apiEndpoint, apiKey, ""}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Error is either an error that occurred during the API request
|
// Error is either an error that occurred during the API request
|
||||||
@@ -61,6 +62,9 @@ func (p *PixelAPI) jsonRequest(method, url string, target interface{}) error {
|
|||||||
if p.apiKey != "" {
|
if p.apiKey != "" {
|
||||||
req.SetBasicAuth("", p.apiKey)
|
req.SetBasicAuth("", p.apiKey)
|
||||||
}
|
}
|
||||||
|
if p.RealIP != "" {
|
||||||
|
req.Header.Set("X-Real-IP", p.RealIP)
|
||||||
|
}
|
||||||
|
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -84,6 +88,9 @@ func (p *PixelAPI) getString(url string) (string, error) {
|
|||||||
if p.apiKey != "" {
|
if p.apiKey != "" {
|
||||||
req.SetBasicAuth("", p.apiKey)
|
req.SetBasicAuth("", p.apiKey)
|
||||||
}
|
}
|
||||||
|
if p.RealIP != "" {
|
||||||
|
req.Header.Set("X-Real-IP", p.RealIP)
|
||||||
|
}
|
||||||
|
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -105,6 +112,9 @@ func (p *PixelAPI) getRaw(url string) (io.ReadCloser, error) {
|
|||||||
if p.apiKey != "" {
|
if p.apiKey != "" {
|
||||||
req.SetBasicAuth("", p.apiKey)
|
req.SetBasicAuth("", p.apiKey)
|
||||||
}
|
}
|
||||||
|
if p.RealIP != "" {
|
||||||
|
req.Header.Set("X-Real-IP", p.RealIP)
|
||||||
|
}
|
||||||
|
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -133,6 +143,9 @@ func (p *PixelAPI) form(
|
|||||||
if p.apiKey != "" {
|
if p.apiKey != "" {
|
||||||
req.SetBasicAuth("", p.apiKey)
|
req.SetBasicAuth("", p.apiKey)
|
||||||
}
|
}
|
||||||
|
if p.RealIP != "" {
|
||||||
|
req.Header.Set("X-Real-IP", p.RealIP)
|
||||||
|
}
|
||||||
|
|
||||||
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||||
|
|
||||||
|
@@ -10,6 +10,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"fornaxian.com/pixeldrain-api/util"
|
||||||
"fornaxian.com/pixeldrain-web/pixelapi"
|
"fornaxian.com/pixeldrain-web/pixelapi"
|
||||||
"github.com/Fornaxian/log"
|
"github.com/Fornaxian/log"
|
||||||
|
|
||||||
@@ -23,7 +24,9 @@ func (wc *WebController) serveFilePreview(w http.ResponseWriter, r *http.Request
|
|||||||
serveFilePreviewDemo(w) // Required for a-ads.com quality check
|
serveFilePreviewDemo(w) // Required for a-ads.com quality check
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var api = pixelapi.New(wc.conf.APIURLInternal, "")
|
apikey, _ := wc.getAPIKey(r)
|
||||||
|
var api = pixelapi.New(wc.conf.APIURLInternal, apikey)
|
||||||
|
api.RealIP = util.RemoteAddress(r)
|
||||||
inf, err := api.GetFileInfo(p.ByName("id"), "?should_a_view_be_added=yes_gimme") // TODO: Error handling
|
inf, err := api.GetFileInfo(p.ByName("id"), "?should_a_view_be_added=yes_gimme") // TODO: Error handling
|
||||||
if err != nil {
|
if err != nil {
|
||||||
wc.serveNotFound(w, r)
|
wc.serveNotFound(w, r)
|
||||||
|
Reference in New Issue
Block a user