Add file viewer branding options
This commit is contained in:
@@ -97,6 +97,8 @@ func (wc *WebController) serveFileViewer(w http.ResponseWriter, r *http.Request,
|
||||
|
||||
templateData.Other = vd
|
||||
|
||||
fileStyleOverride(templateData, files)
|
||||
|
||||
for _, file := range files {
|
||||
if file.AbuseType != "" {
|
||||
w.WriteHeader(http.StatusUnavailableForLegalReasons)
|
||||
@@ -157,6 +159,8 @@ func (wc *WebController) serveListViewer(w http.ResponseWriter, r *http.Request,
|
||||
}
|
||||
templateData.Other = vd
|
||||
|
||||
fileStyleOverride(templateData, list.Files)
|
||||
|
||||
for _, file := range list.Files {
|
||||
if file.AbuseType != "" {
|
||||
w.WriteHeader(http.StatusUnavailableForLegalReasons)
|
||||
@@ -175,6 +179,16 @@ 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].CustomTheme != "" {
|
||||
td.setStyle(userStyle(files[0].CustomTheme))
|
||||
}
|
||||
}
|
||||
|
||||
// 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.
|
||||
|
@@ -21,6 +21,7 @@ import (
|
||||
// TemplateData is a struct that every template expects when being rendered. In
|
||||
// the field Other you can pass your own template-specific variables.
|
||||
type TemplateData struct {
|
||||
tpm *TemplateManager
|
||||
Authenticated bool
|
||||
User pixelapi.UserInfo
|
||||
UserAgent string
|
||||
@@ -45,15 +46,18 @@ type TemplateData struct {
|
||||
Form Form
|
||||
}
|
||||
|
||||
func (td *TemplateData) setStyle(style pixeldrainStyleSheet) {
|
||||
td.Style = style
|
||||
td.UserStyle = template.CSS(style.String())
|
||||
td.BackgroundPattern = style.Background(td.tpm.tpl)
|
||||
}
|
||||
|
||||
func (wc *WebController) newTemplateData(w http.ResponseWriter, r *http.Request) (t *TemplateData) {
|
||||
var style = userStyle(r)
|
||||
t = &TemplateData{
|
||||
Authenticated: false,
|
||||
UserAgent: r.UserAgent(),
|
||||
Style: style,
|
||||
UserStyle: template.CSS(style.String()),
|
||||
BackgroundPattern: style.Background(wc.templates.tpl),
|
||||
APIEndpoint: template.URL(wc.apiURLExternal),
|
||||
tpm: wc.templates,
|
||||
Authenticated: false,
|
||||
UserAgent: r.UserAgent(),
|
||||
APIEndpoint: template.URL(wc.apiURLExternal),
|
||||
|
||||
// Use the user's IP address for making requests
|
||||
PixelAPI: wc.api.RealIP(util.RemoteAddress(r)).RealAgent(r.UserAgent()),
|
||||
@@ -63,6 +67,8 @@ func (wc *WebController) newTemplateData(w http.ResponseWriter, r *http.Request)
|
||||
URLQuery: r.URL.Query(),
|
||||
}
|
||||
|
||||
t.setStyle(userStyleFromRequest(r))
|
||||
|
||||
// If the user is authenticated we'll indentify him and put the user info
|
||||
// into the templatedata. This is used for putting the username in the menu
|
||||
// and stuff like that
|
||||
|
@@ -9,7 +9,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
func userStyle(r *http.Request) (s pixeldrainStyleSheet) {
|
||||
func userStyleFromRequest(r *http.Request) (s pixeldrainStyleSheet) {
|
||||
// Get the chosen style from the URL
|
||||
var style = r.URL.Query().Get("style")
|
||||
|
||||
@@ -20,6 +20,10 @@ func userStyle(r *http.Request) (s pixeldrainStyleSheet) {
|
||||
}
|
||||
}
|
||||
|
||||
return userStyle(style)
|
||||
}
|
||||
|
||||
func userStyle(style string) (s pixeldrainStyleSheet) {
|
||||
switch style {
|
||||
case "classic":
|
||||
s = pixeldrainClassicStyle
|
||||
|
Reference in New Issue
Block a user