Update ad show logic

This commit is contained in:
2020-10-27 11:26:41 +01:00
parent e102c55667
commit 093c64a7bf
2 changed files with 45 additions and 53 deletions

View File

@@ -71,7 +71,7 @@
</button>
<br/>
{{if .Other.ShowAds}}
{{ if and .Other.FileAdsEnabled .Other.UserAdsEnabled }}
<hr/>
<!-- <div id="brave_ref" style="text-align: center; padding: 2px;"> -->
{{if ne (isBrave .UserAgent) true}}
@@ -119,7 +119,7 @@
</div>
<div id="sponsors" class="sponsors">
{{if .Other.ShowAds}}
{{ if and .Other.FileAdsEnabled .Other.UserAdsEnabled }}
{{if eq .Other.AdType 0}}
<!-- 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"
@@ -159,8 +159,12 @@
{{ else if eq .Other.AdType 7}}
<iframe class="sponsors_banner" src="/ad/revenuehits" style="width:728px; height:90px; border:none; padding:0; overflow:hidden;" scrolling="no"></iframe>
{{end}}
{{ else }}
<div style="text-align: center; line-height: 1.5em; font-size: 14px;">
{{ else if not .Other.UserAdsEnabled }}
<div style="text-align: center; line-height: 1.3em; font-size: 13px;">
Thank you for supporting pixeldrain!
</div>
{{ else if not .Other.FileAdsEnabled }}
<div style="text-align: center; line-height: 1.3em; font-size: 13px;">
The uploader of this file disabled advertisements. You can do the same for <a href="/subscribe">only €2 per month</a>!
</div>
{{end}}
@@ -256,7 +260,7 @@
{{template "analytics"}}
{{ if .Other.ShowAds }}
{{ if and .Other.FileAdsEnabled .Other.UserAdsEnabled }}
{{ if eq .Other.AdType 5 }}
<script data-cfasync="false" defer src="//d227cncaprzd7y.cloudfront.net/?acncd=905608"></script>
{{ else if eq .Other.AdType 6}}

View File

@@ -67,12 +67,13 @@ func adType() (i int) {
}
type viewerData struct {
Type string // file or list
CaptchaKey string
ViewToken string
AdType int
ShowAds bool
APIResponse interface{}
Type string // file or list
CaptchaKey string
ViewToken string
AdType int
FileAdsEnabled bool
UserAdsEnabled bool
APIResponse interface{}
}
// ServeFileViewer controller for GET /u/:id
@@ -106,39 +107,30 @@ func (wc *WebController) serveFileViewer(w http.ResponseWriter, r *http.Request,
return
}
showAds := true
if finfo[0].ShowAds == false ||
(templateData.Authenticated && templateData.User.Subscription.DisableAdDisplay) {
showAds = false
}
templateData.OGData = metadataFromFile(finfo[0].FileInfo)
var vd = viewerData{
CaptchaKey: wc.captchaKey(),
ViewToken: wc.viewTokenOrBust(),
AdType: adType(),
FileAdsEnabled: finfo[0].ShowAds,
UserAdsEnabled: !(templateData.Authenticated && templateData.User.Subscription.DisableAdDisplay),
}
if len(ids) > 1 {
templateData.Title = fmt.Sprintf("%d files on pixeldrain", len(finfo))
templateData.Other = viewerData{
Type: "list",
CaptchaKey: wc.captchaKey(),
ViewToken: wc.viewTokenOrBust(),
AdType: adType(),
ShowAds: showAds,
APIResponse: apitype.ListInfo{
Success: true,
Title: "Multiple files",
DateCreated: time.Now(),
Files: finfo,
},
vd.Type = "list"
vd.APIResponse = apitype.ListInfo{
Success: true,
Title: "Multiple files",
DateCreated: time.Now(),
Files: finfo,
}
} else {
templateData.Title = fmt.Sprintf("%s ~ pixeldrain", finfo[0].Name)
templateData.Other = viewerData{
Type: "file",
CaptchaKey: wc.captchaKey(),
ViewToken: wc.viewTokenOrBust(),
AdType: adType(),
ShowAds: showAds,
APIResponse: finfo[0].FileInfo,
}
vd.Type = "file"
vd.APIResponse = finfo[0].FileInfo
}
templateData.Other = vd
var templateName = "file_viewer"
if browserCompat(r.UserAgent()) {
@@ -157,10 +149,11 @@ func (wc *WebController) serveFileViewer(w http.ResponseWriter, r *http.Request,
func (wc *WebController) serveFileViewerDemo(w http.ResponseWriter, r *http.Request) {
templateData := wc.newTemplateData(w, r)
templateData.Other = viewerData{
Type: "file",
CaptchaKey: wc.captchaSiteKey,
AdType: 0, // Always show a-ads on the demo page
ShowAds: true,
Type: "file",
CaptchaKey: wc.captchaSiteKey,
AdType: 0, // Always show a-ads on the demo page
FileAdsEnabled: true,
UserAdsEnabled: true,
APIResponse: map[string]interface{}{
"id": "demo",
"name": "Demo file",
@@ -203,21 +196,16 @@ func (wc *WebController) serveListViewer(w http.ResponseWriter, r *http.Request,
return
}
showAds := true
if (templateData.Authenticated && templateData.User.Subscription.DisableAdDisplay) ||
list.Files[0].ShowAds == false {
showAds = false
}
templateData.Title = fmt.Sprintf("%s ~ pixeldrain", list.Title)
templateData.OGData = metadataFromList(list)
templateData.Other = viewerData{
Type: "list",
CaptchaKey: wc.captchaSiteKey,
ViewToken: wc.viewTokenOrBust(),
AdType: adType(),
ShowAds: showAds,
APIResponse: list,
Type: "list",
CaptchaKey: wc.captchaSiteKey,
ViewToken: wc.viewTokenOrBust(),
AdType: adType(),
FileAdsEnabled: list.Files[0].ShowAds,
UserAdsEnabled: !(templateData.Authenticated && templateData.User.Subscription.DisableAdDisplay),
APIResponse: list,
}
var templateName = "file_viewer"