support skynet

This commit is contained in:
2020-02-04 19:37:46 +01:00
parent aea57286d9
commit 3ebf9785da
20 changed files with 852 additions and 611 deletions

View File

@@ -1,33 +1,33 @@
function AudioViewer(viewer, file, next) {
this.viewer = viewer;
this.file = file;
this.next = next;
this.viewer = viewer
this.file = file
this.next = next
this.container = document.createElement("div");
this.container.classList = "image-container";
this.container.appendChild(document.createElement("br"));
this.container = document.createElement("div")
this.container.classList = "image-container"
this.container.appendChild(document.createElement("br"))
this.icon = document.createElement("img");
this.icon.src = "/res/img/mime/audio.png";
this.container.appendChild(this.icon);
this.icon = document.createElement("img")
this.icon.src = "/res/img/mime/audio.png"
this.container.appendChild(this.icon)
this.container.appendChild(document.createElement("br"));
this.container.appendChild(document.createTextNode(file.name));
this.container.appendChild(document.createElement("br"));
this.container.appendChild(document.createElement("br"));
this.container.appendChild(document.createElement("br"))
this.container.appendChild(document.createTextNode(this.file.name))
this.container.appendChild(document.createElement("br"))
this.container.appendChild(document.createElement("br"))
this.element = document.createElement("audio");
this.element.autoplay = "autoplay";
this.element.controls = "controls";
this.element.style.width = "90%";
this.element.addEventListener("ended", () => { this.next(); }, false);
this.element = document.createElement("audio")
this.element.autoplay = "autoplay"
this.element.controls = "controls"
this.element.style.width = "90%"
this.element.addEventListener("ended", () => { this.next() }, false)
this.source = document.createElement("source");
this.source.src = apiEndpoint+"/file/"+this.file.id;
this.element.appendChild(this.source);
this.container.appendChild(this.element);
this.source = document.createElement("source")
this.source.src = this.file.get_href
this.element.appendChild(this.source)
this.container.appendChild(this.element)
}
AudioViewer.prototype.render = function(parent) {
parent.appendChild(this.container);
parent.appendChild(this.container)
}

View File

@@ -1,27 +1,27 @@
function FileViewer(viewer, file, next) {
this.viewer = viewer;
this.file = file;
this.next = next;
this.viewer = viewer
this.file = file
this.next = next
this.container = document.createElement("div");
this.container.classList = "image-container";
this.container.appendChild(document.createElement("br"));
this.container = document.createElement("div")
this.container.classList = "image-container"
this.container.appendChild(document.createElement("br"))
this.icon = document.createElement("img");
this.icon.src = apiEndpoint+"/"+file.thumbnail_href;
this.container.appendChild(this.icon);
this.icon = document.createElement("img")
this.icon.src = this.file.icon_href
this.container.appendChild(this.icon)
this.container.appendChild(document.createElement("br"));
this.container.appendChild(document.createTextNode(file.name));
this.container.appendChild(document.createElement("br"));
this.container.appendChild(document.createTextNode("Type: "+file.mime_type));
this.container.appendChild(document.createElement("br"));
this.container.appendChild(document.createElement("br"));
this.container.appendChild(document.createElement("br"))
this.container.appendChild(document.createTextNode(file.name))
this.container.appendChild(document.createElement("br"))
this.container.appendChild(document.createTextNode("Type: "+file.mime_type))
this.container.appendChild(document.createElement("br"))
this.container.appendChild(document.createElement("br"))
this.container.appendChild(document.createTextNode(
"Press the 'Download' button in the menu to download this file"
));
))
}
FileViewer.prototype.render = function(parent) {
parent.appendChild(this.container);
parent.appendChild(this.container)
}

View File

@@ -1,88 +1,86 @@
function ImageViewer(viewer, file) {
this.viewer = viewer;
this.file = file;
this.zoomed = false;
this.x = 0;
this.y = 0;
this.dragging = false;
this.viewer = viewer
this.file = file
this.zoomed = false
this.x = 0
this.y = 0
this.dragging = false
this.container = document.createElement("dv");
this.container.classList = "image-container";
// this.container.style.lineHeight = "0";
this.container = document.createElement("dv")
this.container.classList = "image-container"
this.element = document.createElement("img");
this.element.classList = "pannable center drop-shadow";
this.element.src = apiEndpoint+"/file/"+this.file.id;
this.element.addEventListener("dblclick", (e) => { return this.doubleclick(e); });
this.element.addEventListener("doubletap", (e) => { return this.doubleclick(e); });
this.element.addEventListener("mousedown", (e) => { return this.mousedown(e); });
document.addEventListener("mousemove", (e) => { return this.mousemove(e); });
document.addEventListener("mouseup", (e) => { return this.mouseup(e); });
this.element = document.createElement("img")
this.element.classList = "pannable center drop-shadow"
this.element.src = this.file.get_href
this.element.addEventListener("dblclick", (e) => { return this.doubleclick(e) })
this.element.addEventListener("doubletap", (e) => { return this.doubleclick(e) })
this.element.addEventListener("mousedown", (e) => { return this.mousedown(e) })
document.addEventListener("mousemove", (e) => { return this.mousemove(e) })
document.addEventListener("mouseup", (e) => { return this.mouseup(e) })
this.container.appendChild(this.element);
this.container.appendChild(this.element)
}
ImageViewer.prototype.render = function(parent) {
parent.appendChild(this.container);
parent.appendChild(this.container)
}
ImageViewer.prototype.doubleclick = function(e) {
if (this.zoomed) {
this.element.style.maxWidth = "100%";
this.element.style.maxHeight = "100%";
this.element.style.top = "50%";
this.element.style.left = "auto";
this.element.style.transform = "translateY(-50%)";
this.container.style.overflow = "hidden";
this.zoomed = false;
this.element.style.maxWidth = "100%"
this.element.style.maxHeight = "100%"
this.element.style.top = "50%"
this.element.style.left = "auto"
this.element.style.transform = "translateY(-50%)"
this.container.style.overflow = "hidden"
this.zoomed = false
} else {
this.element.style.maxWidth = "none";
this.element.style.maxHeight = "none";
this.element.style.top = "0";
this.element.style.left = "";
this.element.style.transform = "none";
this.container.style.overflow = "scroll";
this.zoomed = true;
this.element.style.maxWidth = "none"
this.element.style.maxHeight = "none"
this.element.style.top = "0"
this.element.style.left = ""
this.element.style.transform = "none"
this.container.style.overflow = "scroll"
this.zoomed = true
}
e.preventDefault();
e.stopPropagation();
return false;
e.preventDefault()
e.stopPropagation()
return false
}
ImageViewer.prototype.mousedown = function(e) {
if (!this.dragging && e.which === 1 && this.zoomed) {
this.x = e.pageX;
this.y = e.pageY;
this.dragging = true;
this.x = e.pageX
this.y = e.pageY
this.dragging = true
e.preventDefault();
e.stopPropagation();
return false;
e.preventDefault()
e.stopPropagation()
return false
}
}
ImageViewer.prototype.mousemove = function(e) {
if (this.dragging) {
this.container.scrollLeft = this.container.scrollLeft - (e.pageX - this.x);
this.container.scrollTop = this.container.scrollTop - (e.pageY - this.y);
this.container.scrollLeft = this.container.scrollLeft - (e.pageX - this.x)
this.container.scrollTop = this.container.scrollTop - (e.pageY - this.y)
this.x = e.pageX;
this.y = e.pageY;
this.x = e.pageX
this.y = e.pageY
e.preventDefault();
e.stopPropagation();
return false;
e.preventDefault()
e.stopPropagation()
return false
}
}
ImageViewer.prototype.mouseup = function(e) {
if (this.dragging) {
this.dragging = false;
this.dragging = false
e.preventDefault();
e.stopPropagation();
return false;
e.preventDefault()
e.stopPropagation()
return false
}
}

View File

@@ -1,13 +1,12 @@
function PDFViewer(viewer, file) {
this.viewer = viewer;
this.file = file;
this.viewer = viewer
this.file = file
this.container = document.createElement("iframe");
this.container.classList = "image-container";
this.container.style.border = "none";
this.container.src = "/res/misc/pdf-viewer/web/viewer.html?file="+apiEndpoint+"/file/"+file.id;
this.container = document.createElement("iframe")
this.container.classList = "image-container"
this.container.style.border = "none"
this.container.src = "/res/misc/pdf-viewer/web/viewer.html?file="+this.file.get_href
}
PDFViewer.prototype.render = function(parent) {
parent.appendChild(this.container);
parent.appendChild(this.container)
}

View File

@@ -1,56 +1,58 @@
function TextViewer(viewer, file) {
this.viewer = viewer;
this.file = file;
this.pre = null;
this.prettyprint = null;
this.viewer = viewer
this.file = file
this.pre = null
this.prettyprint = null
this.container = document.createElement("div");
this.container.classList = "text-container";
this.container = document.createElement("div")
this.container.classList = "text-container"
if (file.name.endsWith(".md") || file.name.endsWith(".markdown") || file.id === "demo") {
this.getMarkdown();
if (this.file.name.endsWith(".md") || this.file.name.endsWith(".markdown") || file.mime_type === "text/demo") {
this.getMarkdown()
} else {
this.getText();
this.getText()
}
}
TextViewer.prototype.getText = function() {
this.pre = document.createElement("pre");
this.pre.classList = "pre-container prettyprint linenums";
this.pre.innerText = "Loading...";
this.container.appendChild(this.pre);
this.pre = document.createElement("pre")
this.pre.classList = "pre-container prettyprint linenums"
this.pre.innerText = "Loading..."
this.container.appendChild(this.pre)
if (this.file.size > 1<<20) { // File larger than 1 MiB
this.pre.innerText = "File is too large to view online.\nPlease download and view it locally.";
return;
this.pre.innerText = "File is too large to view online.\nPlease download and view it locally."
return
}
fetch(apiEndpoint+"/file/"+this.file.id).then(resp => {
if (!resp.ok) { return Promise.reject(resp.status); }
return resp.text();
fetch(this.file.get_href).then(resp => {
if (!resp.ok) { return Promise.reject(resp.status) }
return resp.text()
}).then(resp => {
this.pre.innerText = resp;
this.pre.innerText = resp
// 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.container.appendChild(this.prettyprint);
this.prettyprint = document.createElement("script")
this.prettyprint.src = "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;
});
this.pre.innerText = "Error loading file: "+err
})
}
TextViewer.prototype.getMarkdown = function() {
fetch("/u/"+this.file.id+"/preview").then(resp => {
if (!resp.ok) { return Promise.reject(resp.status); }
return resp.text();
fetch(
domainURL()+window.location.pathname+"/preview"
).then(resp => {
if (!resp.ok) { return Promise.reject(resp.status) }
return resp.text()
}).then(resp => {
this.container.innerHTML = resp;
this.container.innerHTML = resp
}).catch(err => {
this.container.innerText = "Error loading file: "+err;
});
this.container.innerText = "Error loading file: "+err
})
}
TextViewer.prototype.render = function(parent) {
parent.appendChild(this.container);
parent.appendChild(this.container)
}

View File

@@ -1,24 +1,24 @@
function VideoViewer(viewer, file, next) {
this.viewer = viewer;
this.file = file;
this.next = next;
this.viewer = viewer
this.file = file
this.next = next
this.vidContainer = document.createElement("div");
this.vidContainer.classList = "image-container";
this.vidContainer = document.createElement("div")
this.vidContainer.classList = "image-container"
this.vidElement = document.createElement("video");
this.vidElement.autoplay = "autoplay";
this.vidElement.controls = "controls";
this.vidElement.classList = "center drop-shadow";
this.vidElement.addEventListener("ended", () => { this.next(); }, false);
this.vidElement = document.createElement("video")
this.vidElement.autoplay = "autoplay"
this.vidElement.controls = "controls"
this.vidElement.classList = "center drop-shadow"
this.vidElement.addEventListener("ended", () => { this.next() }, false)
this.videoSource = document.createElement("source");
this.videoSource.src = apiEndpoint+"/file/"+this.file.id;
this.videoSource = document.createElement("source")
this.videoSource.src = this.file.get_href
this.vidElement.appendChild(this.videoSource);
this.vidContainer.appendChild(this.vidElement);
this.vidElement.appendChild(this.videoSource)
this.vidContainer.appendChild(this.vidElement)
}
VideoViewer.prototype.render = function(parent) {
parent.appendChild(this.vidContainer);
parent.appendChild(this.vidContainer)
}