fix get viewtoken
This commit is contained in:
@@ -3,6 +3,10 @@ package webcontroller
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"fornaxian.com/pixeldrain-api/util"
|
||||||
|
|
||||||
|
"fornaxian.com/pixeldrain-web/pixelapi"
|
||||||
|
|
||||||
"github.com/Fornaxian/log"
|
"github.com/Fornaxian/log"
|
||||||
"github.com/julienschmidt/httprouter"
|
"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
|
// Redirect the user to the target page
|
||||||
http.Redirect(w, r, r.URL.Query().Get("target"), http.StatusTemporaryRedirect)
|
http.Redirect(w, r, r.URL.Query().Get("target"), http.StatusTemporaryRedirect)
|
||||||
|
|
||||||
// Get a view token
|
api := pixelapi.New(wc.apiURLInternal)
|
||||||
td := wc.newTemplateData(w, r)
|
|
||||||
vt := viewTokenOrBust(td.PixelAPI)
|
// 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
|
// 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")
|
log.Warn("Failed to log view")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -68,7 +68,7 @@ func (wc *WebController) serveFileViewer(w http.ResponseWriter, r *http.Request,
|
|||||||
templateData.Other = viewerData{
|
templateData.Other = viewerData{
|
||||||
Type: "list",
|
Type: "list",
|
||||||
CaptchaKey: wc.captchaKey(),
|
CaptchaKey: wc.captchaKey(),
|
||||||
ViewToken: viewTokenOrBust(templateData.PixelAPI),
|
ViewToken: viewTokenOrBust(wc.systemPixelAPI),
|
||||||
APIResponse: pixelapi.List{
|
APIResponse: pixelapi.List{
|
||||||
Success: true,
|
Success: true,
|
||||||
Title: "Multiple files",
|
Title: "Multiple files",
|
||||||
@@ -81,7 +81,7 @@ func (wc *WebController) serveFileViewer(w http.ResponseWriter, r *http.Request,
|
|||||||
templateData.Other = viewerData{
|
templateData.Other = viewerData{
|
||||||
Type: "file",
|
Type: "file",
|
||||||
CaptchaKey: wc.captchaKey(),
|
CaptchaKey: wc.captchaKey(),
|
||||||
ViewToken: viewTokenOrBust(templateData.PixelAPI),
|
ViewToken: viewTokenOrBust(wc.systemPixelAPI),
|
||||||
APIResponse: finfo[0].FileInfo,
|
APIResponse: finfo[0].FileInfo,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -143,7 +143,7 @@ func (wc *WebController) serveListViewer(w http.ResponseWriter, r *http.Request,
|
|||||||
templateData.Other = viewerData{
|
templateData.Other = viewerData{
|
||||||
Type: "list",
|
Type: "list",
|
||||||
CaptchaKey: wc.captchaSiteKey,
|
CaptchaKey: wc.captchaSiteKey,
|
||||||
ViewToken: viewTokenOrBust(templateData.PixelAPI),
|
ViewToken: viewTokenOrBust(wc.systemPixelAPI),
|
||||||
APIResponse: list,
|
APIResponse: list,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -33,6 +33,10 @@ type WebController struct {
|
|||||||
captchaSiteKey string
|
captchaSiteKey string
|
||||||
|
|
||||||
httpClient *http.Client
|
httpClient *http.Client
|
||||||
|
|
||||||
|
// This API client should only be used for system functions like getting
|
||||||
|
// view tokens. It has no authentication and no IP forwarding
|
||||||
|
systemPixelAPI *pixelapi.PixelAPI
|
||||||
}
|
}
|
||||||
|
|
||||||
// New initializes a new WebController by registering all the request handlers
|
// New initializes a new WebController by registering all the request handlers
|
||||||
@@ -54,6 +58,7 @@ func New(
|
|||||||
apiURLExternal: apiURLExternal,
|
apiURLExternal: apiURLExternal,
|
||||||
sessionCookieDomain: sessionCookieDomain,
|
sessionCookieDomain: sessionCookieDomain,
|
||||||
httpClient: &http.Client{Timeout: time.Minute * 10},
|
httpClient: &http.Client{Timeout: time.Minute * 10},
|
||||||
|
systemPixelAPI: pixelapi.New(apiURLInternal),
|
||||||
}
|
}
|
||||||
wc.templates = NewTemplateManager(resourceDir, apiURLExternal, debugMode)
|
wc.templates = NewTemplateManager(resourceDir, apiURLExternal, debugMode)
|
||||||
wc.templates.ParseTemplates(false)
|
wc.templates.ParseTemplates(false)
|
||||||
|
Reference in New Issue
Block a user