Fix template preview sending invalid view requests

This commit is contained in:
Kailash Nadh 2020-03-08 15:10:51 +05:30
parent ca032c89d6
commit ba87801930
3 changed files with 13 additions and 4 deletions

View File

@ -255,9 +255,14 @@ func handleRegisterCampaignView(c echo.Context) error {
campUUID = c.Param("campUUID")
subUUID = c.Param("subUUID")
)
if _, err := app.queries.RegisterCampaignView.Exec(campUUID, subUUID); err != nil {
app.log.Printf("error registering campaign view: %s", err)
// Exclude dummy hits from template previews.
if campUUID != dummyUUID && subUUID != dummyUUID {
if _, err := app.queries.RegisterCampaignView.Exec(campUUID, subUUID); err != nil {
app.log.Printf("error registering campaign view: %s", err)
}
}
c.Response().Header().Set("Cache-Control", "no-cache")
return c.Blob(http.StatusOK, "image/png", pixelPNG)
}

View File

@ -17,6 +17,10 @@ import (
"github.com/lib/pq"
)
const (
dummyUUID = "00000000-0000-0000-0000-000000000000"
)
// subQueryReq is a "catch all" struct for reading various
// subscriber related requests.
type subQueryReq struct {
@ -57,7 +61,7 @@ type subOptin struct {
var dummySubscriber = models.Subscriber{
Email: "dummy@listmonk.app",
Name: "Dummy Subscriber",
UUID: "00000000-0000-0000-0000-000000000000",
UUID: dummyUUID,
}
// handleGetSubscriber handles the retrieval of a single subscriber by ID.

View File

@ -100,7 +100,7 @@ func handlePreviewTemplate(c echo.Context) error {
// Compile the template.
camp := models.Campaign{
UUID: "00000000-0000-0000-0000-000000000000",
UUID: dummyUUID,
Name: "Dummy Campaign",
Subject: "Dummy Campaign Subject",
FromEmail: "dummy-campaign@listmonk.app",