add option to delete files
This commit is contained in:
@@ -3,32 +3,30 @@ function DetailsWindow(viewer) {
|
||||
this.visible = false
|
||||
this.file = null
|
||||
this.graph = 0
|
||||
this.modal = new Modal(
|
||||
document.getElementById("file_viewer"),
|
||||
() => { this.toggle() },
|
||||
"File Details", "1200px", "1000px",
|
||||
)
|
||||
|
||||
this.divPopup = document.getElementById("details_popup")
|
||||
this.btnDetails = document.getElementById("btn_details")
|
||||
this.btnCloseDetails = document.getElementById("btn_close_details")
|
||||
this.divFileDetails = document.getElementById("info_file_details")
|
||||
let clone = document.getElementById("tpl_details_popup").content.cloneNode(true)
|
||||
this.divFileDetails = clone.querySelector(".info_file_details")
|
||||
this.modal.setBody(clone)
|
||||
|
||||
this.btnDetails.addEventListener("click", () => { this.toggle() })
|
||||
this.btnCloseDetails.addEventListener("click", () => { this.toggle() })
|
||||
this.btnDetails = document.getElementById("btn_details")
|
||||
this.btnDetails.addEventListener("click", () => { this.toggle() })
|
||||
}
|
||||
|
||||
DetailsWindow.prototype.toggle = function() {
|
||||
if (this.visible) {
|
||||
this.divPopup.style.opacity = "0"
|
||||
this.divPopup.style.visibility = "hidden"
|
||||
this.modal.close()
|
||||
this.btnDetails.classList.remove("button_highlight")
|
||||
this.visible = false
|
||||
} else {
|
||||
this.divPopup.style.opacity = "1"
|
||||
this.divPopup.style.visibility = "visible"
|
||||
this.modal.open()
|
||||
this.btnDetails.classList.add("button_highlight")
|
||||
this.visible = true
|
||||
|
||||
// This is a workaround for a chrome bug which makes it so hidden
|
||||
// windows can't be scrolled after they are shown
|
||||
this.divPopup.focus()
|
||||
|
||||
if (this.graph === 0) {
|
||||
this.renderGraph()
|
||||
}
|
||||
@@ -42,8 +40,7 @@ DetailsWindow.prototype.setFile = function(file) {
|
||||
if (this.viewer.isList) {
|
||||
desc = file.description
|
||||
}
|
||||
this.divFileDetails.innerHTML = "<table>"
|
||||
+ "<tr><td>Name<td><td>" + escapeHTML(file.name) + "</td></tr>"
|
||||
this.divFileDetails.innerHTML = "<tr><td>Name<td><td>" + escapeHTML(file.name) + "</td></tr>"
|
||||
+ "<tr><td>URL<td><td><a href=\""+file.link+"\">"+file.link+"</a></td></tr>"
|
||||
+ "<tr><td>Mime Type<td><td>" + escapeHTML(file.mime_type) + "</td></tr>"
|
||||
+ "<tr><td>ID<td><td>" + file.id + "</td></tr>"
|
||||
@@ -51,7 +48,6 @@ DetailsWindow.prototype.setFile = function(file) {
|
||||
+ "<tr><td>Bandwidth<td><td>" + formatDataVolume(file.bandwidth_used, 4) + "</td></tr>"
|
||||
+ "<tr><td>Upload Date<td><td>" + printDate(file.date_created, true, true, true) + "</td></tr>"
|
||||
+ "<tr><td>Description<td><td>" + escapeHTML(desc) + "</td></tr>"
|
||||
+ "</table>"
|
||||
|
||||
if(this.visible && file.timeseries_href !== "") {
|
||||
this.updateGraph(file)
|
||||
|
52
res/include/script/file_viewer/EditWindow.js
Normal file
52
res/include/script/file_viewer/EditWindow.js
Normal file
@@ -0,0 +1,52 @@
|
||||
function EditWindow() {
|
||||
this.visible = false
|
||||
this.modal = new Modal(
|
||||
document.getElementById("file_viewer"),
|
||||
() => { this.toggle() },
|
||||
"Edit File", "1000px", "auto",
|
||||
)
|
||||
|
||||
let clone = document.getElementById("tpl_edit_file").content.cloneNode(true)
|
||||
clone.querySelector(".btn_delete_file").addEventListener("click", () => { this.deleteFile() })
|
||||
this.modal.setBody(clone)
|
||||
|
||||
this.btnEdit = document.getElementById("btn_edit")
|
||||
this.btnEdit.addEventListener("click", () => { this.toggle() })
|
||||
}
|
||||
|
||||
EditWindow.prototype.toggle = function() {
|
||||
if (this.visible) {
|
||||
this.modal.close()
|
||||
this.btnEdit.classList.remove("button_highlight")
|
||||
this.visible = false
|
||||
} else if (!this.visible && this.file.can_edit) {
|
||||
this.modal.open()
|
||||
this.btnEdit.classList.add("button_highlight")
|
||||
this.visible = true
|
||||
}
|
||||
}
|
||||
|
||||
EditWindow.prototype.setFile = function(file) {
|
||||
this.file = file
|
||||
this.modal.setTitle("Editing "+file.name)
|
||||
|
||||
if (this.file.can_edit) {
|
||||
this.btnEdit.style.display = ""
|
||||
} else {
|
||||
this.btnEdit.style.display = "none"
|
||||
}
|
||||
}
|
||||
|
||||
EditWindow.prototype.deleteFile = function() {
|
||||
if (!confirm("Are you sure you want to delete '"+this.file.name+"'?")) {
|
||||
return
|
||||
}
|
||||
|
||||
fetch(
|
||||
this.file.get_href, {method: "DELETE"}
|
||||
).then(resp => {
|
||||
this.modal.setBody(document.createTextNode("This file has been deleted"))
|
||||
}).catch(err => {
|
||||
alert("Error! Could not delete file")
|
||||
})
|
||||
}
|
@@ -1,8 +1,9 @@
|
||||
function Toolbar(viewer) {
|
||||
this.viewer = viewer
|
||||
this.visible = false
|
||||
this.sharebarVisible = false
|
||||
this.currentFile = null
|
||||
this.viewer = viewer
|
||||
this.visible = false
|
||||
this.sharebarVisible = false
|
||||
this.currentFile = null
|
||||
this.editWindow = null
|
||||
|
||||
this.divToolbar = document.getElementById("toolbar")
|
||||
this.divFilePreview = document.getElementById("filepreview")
|
||||
@@ -69,71 +70,67 @@ Toolbar.prototype.toggleSharebar = function() {
|
||||
}
|
||||
|
||||
Toolbar.prototype.download = function() {
|
||||
let triggerDL = (captchaResp = "") => {
|
||||
if (captchaResp === "") {
|
||||
this.downloadFrame.src = this.currentFile.download_href
|
||||
} else {
|
||||
this.downloadFrame.src = this.currentFile.download_href+"&recaptcha_response="+captchaResp
|
||||
}
|
||||
}
|
||||
|
||||
if (captchaKey === "none" || captchaKey === ""){
|
||||
// If the server doesn't support captcha there's no use in checking
|
||||
// availability
|
||||
triggerDL()
|
||||
return
|
||||
}
|
||||
if (recaptchaResponse !== "") {
|
||||
// Captcha already filled in. Use the saved captcha responsse to
|
||||
// download the file
|
||||
triggerDL(recaptchaResponse)
|
||||
|
||||
// Reset the key
|
||||
recaptchaResponse = ""
|
||||
console.debug("Server doesn't support captcha, starting download")
|
||||
this.downloadFrame.src = this.currentFile.download_href
|
||||
return
|
||||
}
|
||||
|
||||
fetch(this.currentFile.availability_href).then(resp => {
|
||||
return resp.json()
|
||||
}).then(resp => {
|
||||
let popupDiv = document.getElementById("captcha_popup")
|
||||
let popupTitle = document.getElementById("captcha_popup_title")
|
||||
let popupContent = document.getElementById("captcha_popup_content")
|
||||
if (this.currentFile.availability === "") {
|
||||
console.debug("File is available, starting download")
|
||||
this.downloadFrame.src = this.currentFile.download_href
|
||||
} else {
|
||||
console.debug("File is not readily available, showing captcha dialog")
|
||||
|
||||
let showCaptcha = (title, text) => {
|
||||
// Create the modal
|
||||
this.captchaModal = new Modal(
|
||||
document.getElementById("file_viewer"),
|
||||
null, title, "500px", "auto",
|
||||
)
|
||||
|
||||
// Clone the popup contents and insert them into the popup
|
||||
let clone = document.getElementById("tpl_captcha_popup").content.cloneNode(true)
|
||||
clone.querySelector(".captcha_text").innerText = text
|
||||
recaptchaElement = clone.querySelector(".captcha_popup_captcha")
|
||||
this.captchaModal.setBody(clone)
|
||||
|
||||
// Set the callback function
|
||||
recaptchaCallback = token => {
|
||||
// Download the file using the recaptcha token
|
||||
this.downloadFrame.src = this.currentFile.download_href+"&recaptcha_response="+token
|
||||
this.captchaModal.close()
|
||||
}
|
||||
|
||||
let showCaptcha = () => {
|
||||
// Load the recaptcha script with a load function
|
||||
let script = document.createElement("script")
|
||||
script.src = "https://www.google.com/recaptcha/api.js?onload=loadCaptcha&render=explicit"
|
||||
document.body.appendChild(script)
|
||||
|
||||
// Show the popup
|
||||
popupDiv.style.opacity = "1"
|
||||
popupDiv.style.visibility = "visible"
|
||||
this.captchaModal.open()
|
||||
}
|
||||
|
||||
if (resp.value === "file_rate_limited_captcha_required") {
|
||||
popupTitle.innerText = "Rate limiting enabled!"
|
||||
popupContent.innerText = "This file is using a suspicious "+
|
||||
"amount of bandwidth relative to its popularity. To "+
|
||||
"continue downloading this file you will have to "+
|
||||
"prove that you're a human first."
|
||||
showCaptcha()
|
||||
} else if (resp.value === "virus_detected_captcha_required") {
|
||||
popupTitle.innerText = "Malware warning!"
|
||||
popupContent.innerText = "According to our scanning "+
|
||||
"systems this file may contain a virus of type '"+
|
||||
resp.extra+"'. You can continue downloading this file at "+
|
||||
"your own risk, but you will have to prove that you're a "+
|
||||
"human first."
|
||||
showCaptcha()
|
||||
} else {
|
||||
console.warn("resp.value not valid: "+resp.value)
|
||||
triggerDL()
|
||||
console.log(this.currentFile.availability)
|
||||
if (this.currentFile.availability === "file_rate_limited_captcha_required") {
|
||||
console.debug("Showing rate limiting captcha")
|
||||
showCaptcha(
|
||||
"Rate limiting enabled!",
|
||||
"This file is using a suspicious amount of bandwidth relative "+
|
||||
"to its popularity. To continue downloading this file you "+
|
||||
"will have to prove that you're a human first.",
|
||||
)
|
||||
} else if (this.currentFile.availability === "virus_detected_captcha_required") {
|
||||
console.debug("Showing virus captcha")
|
||||
showCaptcha(
|
||||
"Malware warning!",
|
||||
"According to our scanning systems this file may contain a "+
|
||||
"virus of type '"+this.currentFile.availability_name+"'. You "+
|
||||
"can continue downloading this file at your own risk, but you "+
|
||||
"will have to prove that you're a human first.",
|
||||
)
|
||||
}
|
||||
}).catch(e => {
|
||||
console.warn("fetch availability failed: "+e)
|
||||
triggerDL()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Toolbar.prototype.copyUrl = function() {
|
||||
@@ -154,23 +151,13 @@ Toolbar.prototype.copyUrl = function() {
|
||||
}, 60000)
|
||||
}
|
||||
|
||||
|
||||
// Called by the google recaptcha script
|
||||
let recaptchaResponse = ""
|
||||
let recaptchaElement = null
|
||||
let recaptchaCallback = null
|
||||
function loadCaptcha(){
|
||||
grecaptcha.render("captcha_popup_captcha", {
|
||||
grecaptcha.render(recaptchaElement, {
|
||||
sitekey: captchaKey,
|
||||
theme: "dark",
|
||||
callback: token => {
|
||||
recaptchaResponse = token
|
||||
document.getElementById("btn_download").click()
|
||||
|
||||
// Hide the popup
|
||||
setTimeout(() => {
|
||||
let popupDiv = document.getElementById("captcha_popup")
|
||||
popupDiv.style.opacity = "0"
|
||||
popupDiv.style.visibility = "hidden"
|
||||
}, 1000)
|
||||
}
|
||||
callback: recaptchaCallback,
|
||||
})
|
||||
}
|
||||
|
@@ -4,6 +4,7 @@ function Viewer(type, viewToken, data) {
|
||||
this.listNavigator = null
|
||||
this.detailsWindow = null
|
||||
this.divFilepreview = null
|
||||
this.file = null
|
||||
this.title = "" // Contains either the file name or list title
|
||||
this.listId = ""
|
||||
this.viewToken = ""
|
||||
@@ -14,6 +15,7 @@ function Viewer(type, viewToken, data) {
|
||||
this.viewToken = viewToken
|
||||
this.toolbar = new Toolbar(this)
|
||||
this.detailsWindow = new DetailsWindow(this)
|
||||
this.editWindow = new EditWindow()
|
||||
|
||||
this.divFilepreview = document.getElementById("filepreview")
|
||||
|
||||
@@ -63,7 +65,13 @@ function Viewer(type, viewToken, data) {
|
||||
this.initialized = true
|
||||
}
|
||||
|
||||
Viewer.prototype.getFile = function() {
|
||||
return this.file
|
||||
}
|
||||
|
||||
Viewer.prototype.setFile = function(file) {
|
||||
this.file = file
|
||||
|
||||
if (this.isList) {
|
||||
document.getElementById("file_viewer_headerbar_title").style.lineHeight = "1em"
|
||||
document.getElementById("file_viewer_list_title").innerText = this.title
|
||||
@@ -76,6 +84,7 @@ Viewer.prototype.setFile = function(file) {
|
||||
|
||||
// Relay the file change event to all components
|
||||
this.detailsWindow.setFile(file)
|
||||
this.editWindow.setFile(file)
|
||||
this.toolbar.setFile(file)
|
||||
|
||||
// Register a new view. We don't care what this returns becasue we can't
|
||||
@@ -169,6 +178,7 @@ Viewer.prototype.keyboardEvent = function(evt) {
|
||||
return // prevent custom shortcuts from interfering with system shortcuts
|
||||
}
|
||||
|
||||
console.debug("Key pressed: "+evt.keyCode)
|
||||
switch (evt.keyCode) {
|
||||
case 65: // A or left arrow key go to previous file
|
||||
case 37:
|
||||
@@ -200,6 +210,9 @@ Viewer.prototype.keyboardEvent = function(evt) {
|
||||
case 73: // I to open the details window
|
||||
this.detailsWindow.toggle()
|
||||
break
|
||||
case 69: // E to open the edit window
|
||||
this.editWindow.toggle()
|
||||
break
|
||||
case 81: // Q to close the window
|
||||
window.close()
|
||||
break
|
||||
@@ -217,35 +230,28 @@ function escapeHTML(str) {
|
||||
}
|
||||
|
||||
function fileFromAPIResp(resp) {
|
||||
let file = {
|
||||
id: resp.id,
|
||||
name: resp.name,
|
||||
mime_type: resp.mime_type,
|
||||
size: resp.size,
|
||||
date_created: new Date(resp.date_upload),
|
||||
date_last_view: new Date(resp.date_last_view),
|
||||
views: resp.views,
|
||||
bandwidth_used: resp.bandwidth_used,
|
||||
description: "",
|
||||
icon_href: apiEndpoint+"/file/"+resp.id+"/thumbnail",
|
||||
get_href: apiEndpoint+"/file/"+resp.id,
|
||||
download_href: apiEndpoint+"/file/"+resp.id+"?download",
|
||||
availability_href: apiEndpoint+"/file/"+resp.id+"/availability",
|
||||
view_href: apiEndpoint+"/file/"+resp.id+"/view",
|
||||
timeseries_href: apiEndpoint+"/file/"+resp.id+"/timeseries",
|
||||
link: domainURL()+"/u/"+resp.id,
|
||||
resp.date_created = new Date(resp.date_upload)
|
||||
resp.date_last_view = new Date(resp.date_last_view)
|
||||
resp.icon_href = apiEndpoint+"/file/"+resp.id+"/thumbnail"
|
||||
resp.get_href = apiEndpoint+"/file/"+resp.id
|
||||
resp.download_href = apiEndpoint+"/file/"+resp.id+"?download"
|
||||
resp.view_href = apiEndpoint+"/file/"+resp.id+"/view"
|
||||
resp.timeseries_href = apiEndpoint+"/file/"+resp.id+"/timeseries"
|
||||
resp.link = domainURL()+"/u/"+resp.id
|
||||
if (resp.description === undefined) {
|
||||
resp.description = ""
|
||||
}
|
||||
if (resp.description !== undefined) {
|
||||
file.description = resp.description
|
||||
}
|
||||
return file
|
||||
|
||||
console.debug("New file:")
|
||||
console.debug(resp)
|
||||
|
||||
return resp
|
||||
}
|
||||
function fileFromSkyNet(resp) {
|
||||
let file = fileFromAPIResp(resp)
|
||||
file.icon_href = "/res/img/mime/empty.png"
|
||||
file.get_href = "https://sky.pixeldrain.com/file/"+resp.id
|
||||
file.download_href = "https://sky.pixeldrain.com/file/"+resp.id+"?attachment=1"
|
||||
file.availability_href = ""
|
||||
file.get_href = "https://skydrain.net/file/"+resp.id
|
||||
file.download_href = "https://skydrain.net/file/"+resp.id+"?attachment=1"
|
||||
file.view_href = ""
|
||||
file.timeseries_href = ""
|
||||
file.link = domainURL()+"/s/"+resp.id
|
||||
|
Reference in New Issue
Block a user