Files
fnx_web/webcontroller/ad_click.go

45 lines
1.2 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
2020-02-26 17:34:01 +01:00
w.Header().Set("Referrer-Policy", "origin")
2020-02-21 13:14:21 +01:00
http.Redirect(w, r, r.URL.Query().Get("target"), http.StatusTemporaryRedirect)
2020-02-26 17:34:01 +01:00
// wc.templates.Get().ExecuteTemplate(w, "hide_refer", r.URL.Query().Get("target"))
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: "/",
2020-03-23 15:11:06 +01:00
Expires: time.Now().AddDate(0, 0, 2),
2020-02-23 12:27:35 +01:00
})
// Redirect the user to the home page
http.Redirect(w, r, "/", http.StatusTemporaryRedirect)
}