+{/if}
+
+
diff --git a/svelte/src/file_viewer/EmbedWindow.svelte b/svelte/src/file_viewer/EmbedWindow.svelte
index 7ba17e4..c145c9b 100644
--- a/svelte/src/file_viewer/EmbedWindow.svelte
+++ b/svelte/src/file_viewer/EmbedWindow.svelte
@@ -1,4 +1,5 @@
@@ -142,38 +153,8 @@ const example = () => {
You can change the pixeldrain theme for your embedded file. Try the
available themes here.
-
-
-
-
-
-
-
-
-
-
-
-
+
+ set_style(e.detail)}>
{:else}
Direct link
@@ -201,7 +182,7 @@ const example = () => {
Copy HTML
{/if}
-
-
+
diff --git a/svelte/src/file_viewer/FileViewer.svelte b/svelte/src/file_viewer/FileViewer.svelte
index bb56dc1..531e93e 100644
--- a/svelte/src/file_viewer/FileViewer.svelte
+++ b/svelte/src/file_viewer/FileViewer.svelte
@@ -19,6 +19,7 @@ import Sharebar from "./Sharebar.svelte";
import GalleryView from "./GalleryView.svelte";
import Spinner from "../util/Spinner.svelte";
import Downloader from "./Downloader.svelte";
+import CustomBanner from "./CustomBanner.svelte";
let loading = true
let embedded = false
@@ -145,6 +146,10 @@ const open_list = l => {
// correct file is opened
is_list = true
+ if (l.files.length !== 0) {
+ apply_customizations(l.files[0])
+ }
+
hash_change()
}
const hash_change = () => {
@@ -200,6 +205,8 @@ const open_file_index = async index => {
document.title = file.name+" ~ pixeldrain"
}
+ apply_customizations(file)
+
// Register a file view
fetch(window.api_endpoint + "/file/" + file.id + "/view", {
method: "POST",
@@ -215,6 +222,30 @@ const toggle_gallery = () => {
}
}
+// Premium page customizations. In the gallery view we will use the
+// customizations for the first file in the list, else we simply use the
+// selected file. In most cases they are all the same so the user won't notice
+// any change
+let file_preview_background
+let custom_header = ""
+let custom_background = ""
+let custom_footer = ""
+const apply_customizations = file => {
+ if (file.custom_header) {
+ custom_header = window.api_endpoint+"/file/"+file.custom_header
+ }
+ if (file.custom_footer) {
+ custom_footer = window.api_endpoint+"/file/"+file.custom_footer
+ }
+
+ if (file.custom_background) {
+ custom_background = window.api_endpoint+"/file/"+file.custom_background
+ file_preview_background.style.backgroundImage = "url('"+custom_background+"')"
+ } else {
+ file_preview_background.style.backgroundImage = ""
+ }
+}
+
let supports_fullscreen = !!document.documentElement.requestFullscreen
let fullscreen = false
const toggle_fullscreen = () => {
@@ -378,6 +409,8 @@ const keyboard_event = evt => {
{/if}
+
+
+
+
diff --git a/webcontroller/file_viewer.go b/webcontroller/file_viewer.go
index a63da8e..a059f70 100644
--- a/webcontroller/file_viewer.go
+++ b/webcontroller/file_viewer.go
@@ -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.
diff --git a/webcontroller/templates.go b/webcontroller/templates.go
index 9e0b4f7..ad3de86 100644
--- a/webcontroller/templates.go
+++ b/webcontroller/templates.go
@@ -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
diff --git a/webcontroller/user_style.go b/webcontroller/user_style.go
index 338b431..8c353ac 100644
--- a/webcontroller/user_style.go
+++ b/webcontroller/user_style.go
@@ -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