Theming changes

This commit is contained in:
2022-06-07 14:43:01 +02:00
parent aed4c3b301
commit 6bed9e9374
96 changed files with 649 additions and 495 deletions

View File

@@ -2,6 +2,7 @@ package webcontroller
import (
"fmt"
"html/template"
"net/http"
"strings"
"time"
@@ -24,12 +25,35 @@ func browserCompat(ua string) bool {
}
type fileViewerData struct {
Type string `json:"type"` // file or list
APIResponse interface{} `json:"api_response"`
CaptchaKey string `json:"captcha_key"`
ViewToken string `json:"view_token"`
Embedded bool `json:"embedded"`
UserAdsEnabled bool `json:"user_ads_enabled"`
Type string `json:"type"` // file or list
APIResponse interface{} `json:"api_response"`
CaptchaKey string `json:"captcha_key"`
ViewToken string `json:"view_token"`
Embedded bool `json:"embedded"`
UserAdsEnabled bool `json:"user_ads_enabled"`
ThemeURI template.URL `json:"theme_uri"`
}
func (vd *fileViewerData) themeOverride(r *http.Request, files []pixelapi.ListFile) {
vd.ThemeURI = "/theme.css"
var theme = r.URL.Query().Get("style")
var hue = r.URL.Query().Get("hue")
if files[0].Branding != nil {
if theme == "" {
theme = files[0].Branding["theme"]
}
if hue == "" {
hue = files[0].Branding["hue"]
}
}
if theme != "" {
vd.ThemeURI += template.URL("?style=" + theme)
if hue != "" {
vd.ThemeURI += template.URL("&hue=" + hue)
}
}
}
// ServeFileViewer controller for GET /u/:id
@@ -95,10 +119,9 @@ func (wc *WebController) serveFileViewer(w http.ResponseWriter, r *http.Request,
vd.Embedded = true
}
vd.themeOverride(r, files)
templateData.Other = vd
fileStyleOverride(templateData, files)
for _, file := range files {
if file.AbuseType != "" {
w.WriteHeader(http.StatusUnavailableForLegalReasons)
@@ -157,9 +180,9 @@ func (wc *WebController) serveListViewer(w http.ResponseWriter, r *http.Request,
if _, ok := r.URL.Query()["embed"]; ok {
vd.Embedded = true
}
templateData.Other = vd
fileStyleOverride(templateData, list.Files)
vd.themeOverride(r, list.Files)
templateData.Other = vd
for _, file := range list.Files {
if file.AbuseType != "" {
@@ -179,16 +202,6 @@ func (wc *WebController) serveListViewer(w http.ResponseWriter, r *http.Request,
}
}
func fileStyleOverride(td *TemplateData, files []pixelapi.ListFile) {
if len(files) == 0 {
return
}
if files[0].Branding != nil && files[0].Branding["theme"] != "" {
td.setStyle(userStyle(files[0].Branding["theme"]))
}
}
// ServeFileViewerDemo is a dummy API response that responds with info about a
// non-existent demo file. This is required by the a-ads ad network to allow for
// automatic checking of the presence of the ad unit on this page.