Files
fnx_web/webcontroller/ad_click.go

42 lines
1.1 KiB
Go
Raw Normal View History

2020-02-21 13:14:21 +01:00
package webcontroller
import (
"net/http"
2020-02-23 12:27:35 +01:00
"time"
2020-02-21 13:14:21 +01:00
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")
}
}
2020-02-23 12:27:35 +01:00
func (wc *WebController) serveCampaignPartner(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
http.SetCookie(w, &http.Cookie{
Name: "pd_campaign",
Value: p.ByName("id"),
Path: "/",
Expires: time.Now().Add(time.Hour * 24),
})
// Redirect the user to the home page
http.Redirect(w, r, "/", http.StatusTemporaryRedirect)
}