Disable video player based on subscription
This commit is contained in:
@@ -23,23 +23,24 @@ function FileViewer(viewer, file, next) {
|
||||
this.fileDetails.style.paddingLeft = "8px"
|
||||
this.fileDetails.style.verticalAlign = "middle"
|
||||
|
||||
this.fileDetails.appendChild(document.createTextNode("Name: "+file.name))
|
||||
this.fileDetails.appendChild(document.createTextNode("Name: " + file.name))
|
||||
this.fileDetails.appendChild(document.createElement("br"))
|
||||
this.fileDetails.appendChild(document.createTextNode("Type: "+file.mime_type))
|
||||
this.fileDetails.appendChild(document.createTextNode("Type: " + file.mime_type))
|
||||
this.fileDetails.appendChild(document.createElement("br"))
|
||||
this.fileDetails.appendChild(document.createTextNode(
|
||||
"No preview is available for this file type. Download to view it locally"
|
||||
))
|
||||
this.fileDetails.appendChild(document.createElement("br"))
|
||||
|
||||
this.btnDL = document.getElementById("btn_download").cloneNode(true)
|
||||
this.btnDL = document.createElement("button")
|
||||
this.btnDL.addEventListener("click", () => { viewer.toolbar.download() })
|
||||
this.btnDL.innerHTML = `<i class="icon">save</i> Download`
|
||||
this.btnDL.classList = "button_highlight"
|
||||
this.fileDetails.appendChild(this.btnDL)
|
||||
|
||||
this.container.appendChild(this.fileDetails)
|
||||
}
|
||||
|
||||
FileViewer.prototype.render = function(parent) {
|
||||
FileViewer.prototype.render = function (parent) {
|
||||
parent.appendChild(this.container)
|
||||
}
|
||||
|
@@ -35,7 +35,7 @@ TextViewer.prototype.getCode = function () {
|
||||
|
||||
// Load prettyprint script
|
||||
this.prettyprint = document.createElement("script")
|
||||
this.prettyprint.src = "https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js?skin=desert"
|
||||
this.prettyprint.src = `{{noescape "https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js?skin=desert"}}`
|
||||
this.container.appendChild(this.prettyprint)
|
||||
}).catch(err => {
|
||||
this.pre.innerText = "Error loading file: " + err
|
||||
|
@@ -2,27 +2,74 @@ function VideoViewer(viewer, file, next) {
|
||||
this.viewer = viewer
|
||||
this.file = file
|
||||
this.next = next
|
||||
|
||||
this.vidContainer = document.createElement("div")
|
||||
this.vidContainer.classList = "image-container"
|
||||
|
||||
this.vidElement = document.createElement("video")
|
||||
this.vidElement.controls = "controls"
|
||||
this.vidElement.playsInline = "playsInline"
|
||||
this.vidElement.classList = "center drop_shadow"
|
||||
this.vidElement.addEventListener("ended", () => { this.next() }, false)
|
||||
if (!embeddedViewer) {
|
||||
this.vidElement.autoplay = "autoplay"
|
||||
}
|
||||
|
||||
this.videoSource = document.createElement("source")
|
||||
this.videoSource.src = this.file.get_href
|
||||
this.videoSource.type = this.file.mime_type
|
||||
|
||||
this.vidElement.appendChild(this.videoSource)
|
||||
this.vidContainer.appendChild(this.vidElement)
|
||||
}
|
||||
|
||||
VideoViewer.prototype.render = function (parent) {
|
||||
parent.appendChild(this.vidContainer)
|
||||
if (this.file.allow_video_player) {
|
||||
let vidContainer = document.createElement("div")
|
||||
vidContainer.classList = "image-container"
|
||||
|
||||
let vidElement = document.createElement("video")
|
||||
vidElement.controls = "controls"
|
||||
vidElement.playsInline = "playsInline"
|
||||
vidElement.classList = "center drop_shadow"
|
||||
vidElement.addEventListener("ended", () => { this.next() }, false)
|
||||
if (!embeddedViewer) {
|
||||
vidElement.autoplay = "autoplay"
|
||||
}
|
||||
|
||||
let videoSource = document.createElement("source")
|
||||
videoSource.src = this.file.get_href
|
||||
videoSource.type = this.file.mime_type
|
||||
|
||||
vidElement.appendChild(videoSource)
|
||||
vidContainer.appendChild(vidElement)
|
||||
parent.appendChild(vidContainer)
|
||||
|
||||
// Possible fix for ios 15 video bug?
|
||||
this.videoSource.src = this.file.get_href
|
||||
this.videoSource.type = this.file.mime_type
|
||||
} else {
|
||||
let container = document.createElement("div")
|
||||
container.classList = "image-container"
|
||||
container.appendChild(document.createElement("br"))
|
||||
|
||||
let title = document.createElement("h1")
|
||||
title.innerText = "This is a video file on pixeldrain"
|
||||
container.appendChild(title)
|
||||
|
||||
let icon = document.createElement("img")
|
||||
icon.style.display = "inline-block"
|
||||
icon.style.verticalAlign = "middle"
|
||||
icon.src = this.file.icon_href
|
||||
container.appendChild(icon)
|
||||
|
||||
let fileDetails = document.createElement("div")
|
||||
fileDetails.style.display = "inline-block"
|
||||
fileDetails.style.textAlign = "left"
|
||||
fileDetails.style.paddingLeft = "8px"
|
||||
fileDetails.style.verticalAlign = "middle"
|
||||
fileDetails.style.maxWidth = "600px"
|
||||
|
||||
fileDetails.appendChild(document.createTextNode(
|
||||
`The online video player on pixeldrain has been disabled due to
|
||||
repeated abuse. You can still watch videos online by upgrading to
|
||||
Pro. Or download the video and watch it locally on your computer.`,
|
||||
))
|
||||
fileDetails.appendChild(document.createElement("br"))
|
||||
|
||||
let upgradeBtn = document.createElement("a")
|
||||
upgradeBtn.innerHTML = `<i class="icon">upgrade</i> Upgrade to Pro`
|
||||
upgradeBtn.classList = "button button_highlight"
|
||||
upgradeBtn.href = `{{noescape "https://www.patreon.com/join/pixeldrain/checkout?rid=5291427&cadence=12"}}`
|
||||
fileDetails.appendChild(upgradeBtn)
|
||||
|
||||
let downloadBtn = document.createElement("button")
|
||||
downloadBtn.innerHTML = `<i class="icon">save</i> Download`
|
||||
downloadBtn.addEventListener("click", () => { this.viewer.toolbar.download() })
|
||||
fileDetails.appendChild(downloadBtn)
|
||||
|
||||
container.appendChild(fileDetails)
|
||||
parent.appendChild(container)
|
||||
}
|
||||
}
|
||||
|
@@ -23,7 +23,7 @@
|
||||
|
||||
<script>
|
||||
window.api_endpoint = '{{.APIEndpoint}}';
|
||||
const initialNode = {{.Other}};
|
||||
window.initial_file = {{.Other.APIResponse}};
|
||||
</script>
|
||||
|
||||
<link rel='stylesheet' href='/res/svelte/file_viewer.css'>
|
||||
|
@@ -239,8 +239,11 @@
|
||||
<div class="feat_label">
|
||||
Online file previews
|
||||
</div>
|
||||
<div class="feat_normal">
|
||||
View image, audio, PDF and text files directly in your web browser
|
||||
</div>
|
||||
<div class="feat_pro">
|
||||
View image, video, audio, PDF and text files directly in your web browser
|
||||
All of the previous formats plus video streaming
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
|
@@ -46,13 +46,8 @@ func (vd *viewerData) adType(files []pixelapi.ListFile) {
|
||||
}
|
||||
|
||||
var avgSize int64
|
||||
var nudity = false
|
||||
for _, v := range files {
|
||||
avgSize += v.Size
|
||||
|
||||
if strings.HasPrefix(v.MimeType, "video/") {
|
||||
nudity = true
|
||||
}
|
||||
}
|
||||
avgSize /= int64(len(files))
|
||||
|
||||
@@ -98,29 +93,10 @@ func (vd *viewerData) adType(files []pixelapi.ListFile) {
|
||||
// or 1 we need to give it n=2. We can use this function to make other
|
||||
// splits like 1/3 1/4, etc
|
||||
|
||||
if nudity {
|
||||
// Brave and a-ads don't care about nudity. I'm not sure about ads.plus
|
||||
switch i := rand.Intn(10); i {
|
||||
case 0, 1:
|
||||
case 0:
|
||||
vd.AdBannerType = brave
|
||||
case 2, 3, 4, 5, 6:
|
||||
vd.AdBannerType = adsPlus
|
||||
case 7:
|
||||
vd.AdBannerType = publisherrest1
|
||||
case 8:
|
||||
vd.AdBannerType = publisherrest2
|
||||
case 9:
|
||||
vd.AdBannerType = publisherrest3
|
||||
default:
|
||||
panic(fmt.Errorf("random number generator returned unrecognised number: %d", i))
|
||||
}
|
||||
} else {
|
||||
// PixFuture does not allow nudity, so that's what we'll show on all
|
||||
// files which are safe
|
||||
switch i := rand.Intn(10); i {
|
||||
case 0, 1:
|
||||
vd.AdBannerType = brave
|
||||
case 2, 3:
|
||||
case 1, 2, 3:
|
||||
vd.AdBannerType = adsPlus
|
||||
case 4, 5, 6:
|
||||
vd.AdBannerType = pixFuture
|
||||
@@ -133,7 +109,6 @@ func (vd *viewerData) adType(files []pixelapi.ListFile) {
|
||||
default:
|
||||
panic(fmt.Errorf("random number generator returned unrecognised number: %d", i))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ServeFileViewer controller for GET /u/:id
|
||||
|
@@ -140,6 +140,7 @@ func (tm *TemplateManager) ParseTemplates(silent bool) {
|
||||
"div": tm.div,
|
||||
"formatData": tm.formatData,
|
||||
"formatSC": tm.formatSC,
|
||||
"noescape": tm.noEscape,
|
||||
})
|
||||
|
||||
// Parse dynamic templates
|
||||
@@ -295,6 +296,9 @@ func (tm *TemplateManager) formatSC(amt float64) string {
|
||||
}
|
||||
return fmtSize(amt/1e-24, "H")
|
||||
}
|
||||
func (tm *TemplateManager) noEscape(t string) template.HTML {
|
||||
return template.HTML(t)
|
||||
}
|
||||
|
||||
func detectInt(i interface{}) int {
|
||||
switch v := i.(type) {
|
||||
|
Reference in New Issue
Block a user