change hoew viewtokens are aqcuired
This commit is contained in:
@@ -17,15 +17,12 @@ func (wc *WebController) serveAdClick(w http.ResponseWriter, r *http.Request, p
|
||||
|
||||
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)
|
||||
// The Real IP is used in the API server to determine that the view is not
|
||||
// fake
|
||||
api.RealIP = util.RemoteAddress(r)
|
||||
|
||||
// Log a view on the file
|
||||
if err := api.PostFileView(p.ByName("id"), vt); err != nil {
|
||||
if err := api.PostFileView(p.ByName("id"), wc.viewTokenOrBust()); err != nil {
|
||||
log.Warn("Failed to log view")
|
||||
}
|
||||
}
|
||||
|
@@ -16,9 +16,9 @@ import (
|
||||
"github.com/julienschmidt/httprouter"
|
||||
)
|
||||
|
||||
func viewTokenOrBust(api *pixelapi.PixelAPI) (t string) {
|
||||
func (wc *WebController) viewTokenOrBust() (t string) {
|
||||
var err error
|
||||
if t, err = api.GetMiscViewToken(); err != nil {
|
||||
if t, err = wc.systemPixelAPI.GetMiscViewToken(); err != nil {
|
||||
log.Error("Could not get viewtoken: %s", err)
|
||||
}
|
||||
return t
|
||||
@@ -68,7 +68,7 @@ func (wc *WebController) serveFileViewer(w http.ResponseWriter, r *http.Request,
|
||||
templateData.Other = viewerData{
|
||||
Type: "list",
|
||||
CaptchaKey: wc.captchaKey(),
|
||||
ViewToken: viewTokenOrBust(wc.systemPixelAPI),
|
||||
ViewToken: wc.viewTokenOrBust(),
|
||||
APIResponse: pixelapi.List{
|
||||
Success: true,
|
||||
Title: "Multiple files",
|
||||
@@ -81,7 +81,7 @@ func (wc *WebController) serveFileViewer(w http.ResponseWriter, r *http.Request,
|
||||
templateData.Other = viewerData{
|
||||
Type: "file",
|
||||
CaptchaKey: wc.captchaKey(),
|
||||
ViewToken: viewTokenOrBust(wc.systemPixelAPI),
|
||||
ViewToken: wc.viewTokenOrBust(),
|
||||
APIResponse: finfo[0].FileInfo,
|
||||
}
|
||||
}
|
||||
@@ -143,7 +143,7 @@ func (wc *WebController) serveListViewer(w http.ResponseWriter, r *http.Request,
|
||||
templateData.Other = viewerData{
|
||||
Type: "list",
|
||||
CaptchaKey: wc.captchaSiteKey,
|
||||
ViewToken: viewTokenOrBust(wc.systemPixelAPI),
|
||||
ViewToken: wc.viewTokenOrBust(),
|
||||
APIResponse: list,
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user