add banner ad view counting
This commit is contained in:
@@ -2,6 +2,7 @@ package pixelapi
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/url"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -36,3 +37,9 @@ type FileInfo struct {
|
||||
func (p *PixelAPI) GetFileInfo(id string) (resp FileInfo, err error) {
|
||||
return resp, p.jsonRequest("GET", p.apiEndpoint+"/file/"+id+"/info", &resp)
|
||||
}
|
||||
|
||||
func (p *PixelAPI) PostFileView(id, viewtoken string) (err error) {
|
||||
vals := url.Values{}
|
||||
vals.Set("token", viewtoken)
|
||||
return p.form("POST", p.apiEndpoint+"/file/"+id+"/view", vals, nil, true)
|
||||
}
|
||||
|
@@ -56,8 +56,8 @@ function Viewer(type, viewToken, data) {
|
||||
this.setFile(fileFromSkyNet(data))
|
||||
}
|
||||
|
||||
// this.renderSponsors()
|
||||
// window.addEventListener("resize", e => { this.renderSponsors(e) })
|
||||
this.renderSponsorsSimple()
|
||||
window.addEventListener("resize", e => { this.renderSponsorsSimple() })
|
||||
|
||||
// Register keyboard shortcuts
|
||||
document.addEventListener("keydown", e => { this.keyboardEvent(e) })
|
||||
@@ -138,6 +138,24 @@ Viewer.prototype.setFile = function(file) {
|
||||
}
|
||||
}
|
||||
|
||||
Viewer.prototype.renderSponsorsSimple = function() {
|
||||
let scale = 1
|
||||
let scaleWidth = 1
|
||||
let scaleHeight = 1
|
||||
let minWidth = 768
|
||||
let minHeight = 1000
|
||||
|
||||
if (window.innerWidth < minWidth) {
|
||||
scaleWidth = window.innerWidth/minWidth
|
||||
}
|
||||
if (window.innerHeight < minHeight) {
|
||||
scaleHeight = window.innerHeight/minHeight
|
||||
}
|
||||
scale = scaleWidth < scaleHeight ? scaleWidth : scaleHeight
|
||||
|
||||
document.querySelector(".sponsors").style.height = (scale*128)+"px"
|
||||
}
|
||||
|
||||
// Viewer.prototype.renderSponsors = function() {
|
||||
// let scale = 1
|
||||
// let scaleWidth = 1
|
||||
|
BIN
res/static/img/misc/banner_as.png
Normal file
BIN
res/static/img/misc/banner_as.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 193 KiB |
@@ -105,6 +105,12 @@
|
||||
<div class="center" style="width: 100px; height: 100px;">{{template "spinner.svg" .}}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="sponsors" class="sponsors">
|
||||
<a href="/click/DtZ3hHT9?target=https%3A%2F%2Fwww.embedded-world.de%2Fen%2Fbecome-visitor">
|
||||
<img src="/res/img/misc/banner_as.png" style="display: block; margin: auto; height: 100%;" />
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<template id="tpl_details_popup">
|
||||
|
22
webcontroller/ad_click.go
Normal file
22
webcontroller/ad_click.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package webcontroller
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"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)
|
||||
|
||||
// Get a view token
|
||||
td := wc.newTemplateData(w, r)
|
||||
vt := viewTokenOrBust(td.PixelAPI)
|
||||
|
||||
// Log a view on the file
|
||||
if err := td.PixelAPI.PostFileView(p.ByName("id"), vt); err != nil {
|
||||
log.Warn("Failed to log view")
|
||||
}
|
||||
}
|
@@ -98,6 +98,7 @@ func New(
|
||||
r.GET(p+"/widgets" /* */, wc.serveTemplate("widgets", false))
|
||||
r.GET(p+"/about" /* */, wc.serveTemplate("about", false))
|
||||
r.GET(p+"/appearance" /* */, wc.serveTemplate("appearance", false))
|
||||
r.GET(p+"/click/:id" /* */, wc.serveAdClick)
|
||||
|
||||
// User account pages
|
||||
r.GET(p+"/register" /* */, wc.serveForm(wc.registerForm, false))
|
||||
|
Reference in New Issue
Block a user