Files
fnx_web/webcontroller/ad_click.go

29 lines
726 B
Go
Raw Normal View History

2020-02-21 13:14:21 +01:00
package webcontroller
import (
"net/http"
2020-02-21 14:23:29 +01:00
"fornaxian.com/pixeldrain-api/util"
"fornaxian.com/pixeldrain-web/pixelapi"
2020-02-21 13:14:21 +01:00
"github.com/Fornaxian/log"
"github.com/julienschmidt/httprouter"
)
func (wc *WebController) serveAdClick(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
// Redirect the user to the target page
http.Redirect(w, r, r.URL.Query().Get("target"), http.StatusTemporaryRedirect)
2020-02-21 14:23:29 +01:00
api := pixelapi.New(wc.apiURLInternal)
2020-02-21 14:32:06 +01:00
// The Real IP is used in the API server to determine that the view is not
// fake
2020-02-21 14:23:29 +01:00
api.RealIP = util.RemoteAddress(r)
2020-02-21 13:14:21 +01:00
// Log a view on the file
2020-02-21 14:32:06 +01:00
if err := api.PostFileView(p.ByName("id"), wc.viewTokenOrBust()); err != nil {
2020-02-21 13:14:21 +01:00
log.Warn("Failed to log view")
}
}