switch between amarula and a-ads
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
package init
|
package init
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
"fornaxian.com/pixeldrain-web/webcontroller"
|
"fornaxian.com/pixeldrain-web/webcontroller"
|
||||||
"github.com/Fornaxian/config"
|
"github.com/Fornaxian/config"
|
||||||
@@ -34,6 +36,9 @@ maintenance_mode = false
|
|||||||
func Init(r *httprouter.Router, prefix string, setLogLevel bool) {
|
func Init(r *httprouter.Router, prefix string, setLogLevel bool) {
|
||||||
log.Info("Starting web UI server (PID %v)", os.Getpid())
|
log.Info("Starting web UI server (PID %v)", os.Getpid())
|
||||||
|
|
||||||
|
// Seed the RNG
|
||||||
|
rand.Seed(time.Now().UnixNano())
|
||||||
|
|
||||||
var webconf = &PixelWebConfig{}
|
var webconf = &PixelWebConfig{}
|
||||||
var _, err = config.New(
|
var _, err = config.New(
|
||||||
DefaultConfig,
|
DefaultConfig,
|
||||||
|
@@ -50,8 +50,8 @@ function Viewer(type, viewToken, data) {
|
|||||||
this.setFile(fileFromSkyNet(data))
|
this.setFile(fileFromSkyNet(data))
|
||||||
}
|
}
|
||||||
|
|
||||||
this.renderSponsorsSimple()
|
this.renderSponsors()
|
||||||
window.addEventListener("resize", e => { this.renderSponsorsSimple() })
|
window.addEventListener("resize", e => { this.renderSponsors() })
|
||||||
|
|
||||||
// Register keyboard shortcuts
|
// Register keyboard shortcuts
|
||||||
document.addEventListener("keydown", e => { this.keyboardEvent(e) })
|
document.addEventListener("keydown", e => { this.keyboardEvent(e) })
|
||||||
@@ -132,12 +132,12 @@ Viewer.prototype.setFile = function(file) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Viewer.prototype.renderSponsorsSimple = function() {
|
Viewer.prototype.renderSponsors = function() {
|
||||||
let scaleWidth = 1
|
let scaleWidth = 1
|
||||||
let scaleHeight = 1
|
let scaleHeight = 1
|
||||||
let minWindowHeight = 1000
|
let minWindowHeight = 800
|
||||||
let bannerWidth = 720
|
let bannerWidth = document.querySelector(".sponsors_banner").offsetWidth
|
||||||
let bannerHeight = 120
|
let bannerHeight = document.querySelector(".sponsors_banner").offsetHeight
|
||||||
|
|
||||||
if (window.innerWidth < bannerWidth) {
|
if (window.innerWidth < bannerWidth) {
|
||||||
scaleWidth = window.innerWidth/bannerWidth
|
scaleWidth = window.innerWidth/bannerWidth
|
||||||
@@ -146,45 +146,21 @@ Viewer.prototype.renderSponsorsSimple = function() {
|
|||||||
scaleHeight = window.innerHeight/minWindowHeight
|
scaleHeight = window.innerHeight/minWindowHeight
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The smaller scale is the scale we'll use
|
||||||
let scale = scaleWidth < scaleHeight ? scaleWidth : scaleHeight
|
let scale = scaleWidth < scaleHeight ? scaleWidth : scaleHeight
|
||||||
document.querySelector(".sponsors").style.height = (scale*bannerHeight)+"px"
|
|
||||||
|
// Because of the scale transformation the automatic margins don't work
|
||||||
|
// anymore. So we have to manually calculate the margin. Here we take the
|
||||||
|
// width of the viewport - the width of the ad to calculate the amount of
|
||||||
|
// pixels around the ad. We multiply the ad size by the scale we calcualted
|
||||||
|
// to account for the smaller size.
|
||||||
|
let offset = (window.innerWidth - (bannerWidth*scale)) / 2
|
||||||
|
|
||||||
|
document.querySelector(".sponsors").style.height = (bannerHeight*scale)+"px"
|
||||||
|
document.querySelector(".sponsors_banner").style.marginLeft = offset+"px"
|
||||||
|
document.querySelector(".sponsors_banner").style.transform = "scale("+scale+")"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Viewer.prototype.renderSponsors = function() {
|
|
||||||
// let scale = 1
|
|
||||||
// let scaleWidth = 1
|
|
||||||
// let scaleHeight = 1
|
|
||||||
// let minWidth = 728
|
|
||||||
// let minHeight = 800
|
|
||||||
|
|
||||||
// if (window.innerWidth < minWidth) {
|
|
||||||
// scaleWidth = window.innerWidth/minWidth
|
|
||||||
// }
|
|
||||||
// if (window.innerHeight < minHeight) {
|
|
||||||
// scaleHeight = window.innerHeight/minHeight
|
|
||||||
// }
|
|
||||||
// scale = scaleWidth < scaleHeight ? scaleWidth : scaleHeight
|
|
||||||
|
|
||||||
// // Because of the scale transformation the automatic margins don't work
|
|
||||||
// // anymore. So we have to maunally calculate the margin. Where we take the
|
|
||||||
// // width of the viewport - the width of the ad to calculate the amount of
|
|
||||||
// // pixels around the ad. We multiply the ad size by the scale we calcualted
|
|
||||||
// // to account for the smaller size.
|
|
||||||
// let offset = (window.innerWidth - (minWidth*scale)) / 2
|
|
||||||
// if (offset < 0) {
|
|
||||||
// offset = 0
|
|
||||||
// }
|
|
||||||
// document.querySelector(".sponsors > iframe").style.marginLeft = offset+"px"
|
|
||||||
|
|
||||||
// if (scale == 1) {
|
|
||||||
// document.querySelector(".sponsors > iframe").style.transform = "none"
|
|
||||||
// document.querySelector(".sponsors").style.height = "90px"
|
|
||||||
// } else {
|
|
||||||
// document.querySelector(".sponsors > iframe").style.transform = "scale("+scale+")"
|
|
||||||
// document.querySelector(".sponsors").style.height = (scale*90)+"px"
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
Viewer.prototype.keyboardEvent = function(evt) {
|
Viewer.prototype.keyboardEvent = function(evt) {
|
||||||
if (evt.ctrlKey || evt.altKey || evt.metaKey) {
|
if (evt.ctrlKey || evt.altKey || evt.metaKey) {
|
||||||
return // prevent custom shortcuts from interfering with system shortcuts
|
return // prevent custom shortcuts from interfering with system shortcuts
|
||||||
|
@@ -116,7 +116,7 @@
|
|||||||
font-size: 0;
|
font-size: 0;
|
||||||
line-height: 0;
|
line-height: 0;
|
||||||
}
|
}
|
||||||
.file_viewer > .sponsors > iframe {
|
.file_viewer > .sponsors > * {
|
||||||
display: block;
|
display: block;
|
||||||
margin: auto;
|
margin: auto;
|
||||||
transform-origin: 0 0;
|
transform-origin: 0 0;
|
||||||
|
@@ -100,9 +100,19 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="sponsors" class="sponsors">
|
<div id="sponsors" class="sponsors">
|
||||||
<a href="/click/DtZ3hHT9?target=https%3A%2F%2Fwww.amarula-electronics.com/?v=79cba1185463">
|
{{if eq .Other.AdType 0}}
|
||||||
<img src="/res/img/misc/banner_as.png" style="display: block; margin: auto; height: 100%;" />
|
<!-- scrolling="no" is not allowed by the W3C, but overflow: hidden doesn't work in chrome, so I have no choice -->
|
||||||
|
<iframe class="sponsors_banner"
|
||||||
|
data-aa="73974"
|
||||||
|
src="//ad.a-ads.com/73974?size=728x90&background_color={{.Style.Layer1Color.RGB}}&text_color={{.Style.TextColor.RGB}}&title_color={{.Style.HighlightColor.RGB}}&title_hover_color={{.Style.HighlightColor.RGB}}&link_color={{.Style.HighlightColor.RGB}}&link_hover_color={{.Style.HighlightColor.RGB}}"
|
||||||
|
style="width:728px; height:90px; border:none; padding:0; overflow:hidden;"
|
||||||
|
scrolling="no">
|
||||||
|
</iframe>
|
||||||
|
{{else if eq .Other.AdType 1}}
|
||||||
|
<a class="sponsors_banner" style="display: inline-block; width: 576px; height: 96px;" href="/click/DtZ3hHT9?target=https%3A%2F%2Fwww.amarula-electronics.com/?v=79cba1185463">
|
||||||
|
<img src="/res/img/misc/banner_as.png" style="width: 100%; height: 100%" />
|
||||||
</a>
|
</a>
|
||||||
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@@ -3,6 +3,7 @@ package webcontroller
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"math/rand"
|
||||||
"mime"
|
"mime"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -28,10 +29,25 @@ func browserCompat(ua string) bool {
|
|||||||
return strings.Contains(ua, "MSIE") || strings.Contains(ua, "Trident/7.0")
|
return strings.Contains(ua, "MSIE") || strings.Contains(ua, "Trident/7.0")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func adType() (i int) {
|
||||||
|
// Intn returns a number up to n, but never n itself. So it get a random 0
|
||||||
|
// or 1 we need to give it n=2. We can use this function to make other
|
||||||
|
// splits like 1/3 1/4, etc
|
||||||
|
i = rand.Intn(2)
|
||||||
|
|
||||||
|
switch {
|
||||||
|
case i == 1: // 50% of the traffic
|
||||||
|
return 1 // Amarula
|
||||||
|
default:
|
||||||
|
return 0 // A-Ads
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type viewerData struct {
|
type viewerData struct {
|
||||||
Type string // file or list
|
Type string // file or list
|
||||||
CaptchaKey string
|
CaptchaKey string
|
||||||
ViewToken string
|
ViewToken string
|
||||||
|
AdType int
|
||||||
APIResponse interface{}
|
APIResponse interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,6 +85,7 @@ func (wc *WebController) serveFileViewer(w http.ResponseWriter, r *http.Request,
|
|||||||
Type: "list",
|
Type: "list",
|
||||||
CaptchaKey: wc.captchaKey(),
|
CaptchaKey: wc.captchaKey(),
|
||||||
ViewToken: wc.viewTokenOrBust(),
|
ViewToken: wc.viewTokenOrBust(),
|
||||||
|
AdType: adType(),
|
||||||
APIResponse: pixelapi.List{
|
APIResponse: pixelapi.List{
|
||||||
Success: true,
|
Success: true,
|
||||||
Title: "Multiple files",
|
Title: "Multiple files",
|
||||||
@@ -82,6 +99,7 @@ func (wc *WebController) serveFileViewer(w http.ResponseWriter, r *http.Request,
|
|||||||
Type: "file",
|
Type: "file",
|
||||||
CaptchaKey: wc.captchaKey(),
|
CaptchaKey: wc.captchaKey(),
|
||||||
ViewToken: wc.viewTokenOrBust(),
|
ViewToken: wc.viewTokenOrBust(),
|
||||||
|
AdType: adType(),
|
||||||
APIResponse: finfo[0].FileInfo,
|
APIResponse: finfo[0].FileInfo,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -105,6 +123,7 @@ func (wc *WebController) serveFileViewerDemo(w http.ResponseWriter, r *http.Requ
|
|||||||
templateData.Other = viewerData{
|
templateData.Other = viewerData{
|
||||||
Type: "file",
|
Type: "file",
|
||||||
CaptchaKey: wc.captchaSiteKey,
|
CaptchaKey: wc.captchaSiteKey,
|
||||||
|
AdType: 0, // Always show a-ads on the demo page
|
||||||
APIResponse: map[string]interface{}{
|
APIResponse: map[string]interface{}{
|
||||||
"id": "demo",
|
"id": "demo",
|
||||||
"name": "Demo file",
|
"name": "Demo file",
|
||||||
@@ -147,6 +166,7 @@ func (wc *WebController) serveListViewer(w http.ResponseWriter, r *http.Request,
|
|||||||
Type: "list",
|
Type: "list",
|
||||||
CaptchaKey: wc.captchaSiteKey,
|
CaptchaKey: wc.captchaSiteKey,
|
||||||
ViewToken: wc.viewTokenOrBust(),
|
ViewToken: wc.viewTokenOrBust(),
|
||||||
|
AdType: adType(),
|
||||||
APIResponse: list,
|
APIResponse: list,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -235,7 +255,8 @@ func (wc *WebController) serveSkynetViewer(w http.ResponseWriter, r *http.Reques
|
|||||||
templateData.OGData = ""
|
templateData.OGData = ""
|
||||||
templateData.Title = fmt.Sprintf("name ~ Skynet")
|
templateData.Title = fmt.Sprintf("name ~ Skynet")
|
||||||
templateData.Other = viewerData{
|
templateData.Other = viewerData{
|
||||||
Type: "skylink",
|
Type: "skylink",
|
||||||
|
AdType: adType(),
|
||||||
APIResponse: pixelapi.FileInfo{
|
APIResponse: pixelapi.FileInfo{
|
||||||
Success: true,
|
Success: true,
|
||||||
ID: p.ByName("id"),
|
ID: p.ByName("id"),
|
||||||
|
Reference in New Issue
Block a user