Files
fnx_web/webcontroller/ad_click.go

38 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-07-29 17:56:32 +02:00
"fornaxian.tech/pixeldrain_server/util"
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-21 14:32:06 +01:00
// The Real IP is used in the API server to determine that the view is not
// fake
2021-09-21 21:39:28 +02:00
var api = wc.api.RealIP(util.RemoteAddress(r)).RealAgent(r.UserAgent())
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-05-23 13:44:56 +02:00
log.Error("Failed to log view: %s", err)
2020-02-21 13:14:21 +01:00
}
}
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: "/",
2021-06-22 00:34:14 +02:00
Expires: time.Now().AddDate(0, 0, 7),
2020-02-23 12:27:35 +01:00
})
// Redirect the user to the home page
http.Redirect(w, r, "/", http.StatusTemporaryRedirect)
}