fix get viewtoken
This commit is contained in:
@@ -3,6 +3,10 @@ package webcontroller
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"fornaxian.com/pixeldrain-api/util"
|
||||
|
||||
"fornaxian.com/pixeldrain-web/pixelapi"
|
||||
|
||||
"github.com/Fornaxian/log"
|
||||
"github.com/julienschmidt/httprouter"
|
||||
)
|
||||
@@ -11,12 +15,17 @@ func (wc *WebController) serveAdClick(w http.ResponseWriter, r *http.Request, p
|
||||
// Redirect the user to the target page
|
||||
http.Redirect(w, r, r.URL.Query().Get("target"), http.StatusTemporaryRedirect)
|
||||
|
||||
// Get a view token
|
||||
td := wc.newTemplateData(w, r)
|
||||
vt := viewTokenOrBust(td.PixelAPI)
|
||||
api := pixelapi.New(wc.apiURLInternal)
|
||||
|
||||
// Get the view token without authentication
|
||||
vt := viewTokenOrBust(api)
|
||||
|
||||
// Apply authentication and register the view
|
||||
api.APIKey, _ = wc.getAPIKey(r)
|
||||
api.RealIP = util.RemoteAddress(r)
|
||||
|
||||
// Log a view on the file
|
||||
if err := td.PixelAPI.PostFileView(p.ByName("id"), vt); err != nil {
|
||||
if err := api.PostFileView(p.ByName("id"), vt); err != nil {
|
||||
log.Warn("Failed to log view")
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user