diff --git a/res/include/script/file_viewer/viewer_scripts/TextViewer.js b/res/include/script/file_viewer/viewer_scripts/TextViewer.js index c182a09..2fcb99a 100644 --- a/res/include/script/file_viewer/viewer_scripts/TextViewer.js +++ b/res/include/script/file_viewer/viewer_scripts/TextViewer.js @@ -1,7 +1,7 @@ function TextViewer(viewer, file) { - this.viewer = viewer - this.file = file - this.pre = null + this.viewer = viewer + this.file = file + this.pre = null this.prettyprint = null this.container = document.createElement("div") @@ -9,18 +9,20 @@ function TextViewer(viewer, file) { if (this.file.name.endsWith(".md") || this.file.name.endsWith(".markdown") || file.mime_type === "text/demo") { this.getMarkdown() - } else { + } else if (this.file.name.endsWith(".txt")) { this.getText() + } else { + this.getCode() } } -TextViewer.prototype.getText = function() { +TextViewer.prototype.getCode = function () { 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 + 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 } @@ -36,23 +38,43 @@ TextViewer.prototype.getText = function() { 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() { +TextViewer.prototype.getText = function () { + this.pre = document.createElement("pre") + 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 + } + + fetch(this.file.get_href).then(resp => { + if (!resp.ok) { return Promise.reject(resp.status) } + return resp.text() + }).then(resp => { + this.pre.innerText = resp + }).catch(err => { + this.pre.innerText = "Error loading file: " + err + }) +} + +TextViewer.prototype.getMarkdown = function () { fetch( - domainURL()+window.location.pathname+"/preview" + domainURL() + window.location.pathname + "/preview" ).then(resp => { if (!resp.ok) { return Promise.reject(resp.status) } return resp.text() }).then(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) { +TextViewer.prototype.render = function (parent) { parent.appendChild(this.container) } diff --git a/res/template/home.html b/res/template/home.html index 19bdce7..48aa305 100644 --- a/res/template/home.html +++ b/res/template/home.html @@ -132,8 +132,9 @@ an ice storm in Oregon the datacenter where pixeldrain is hosted in North America was cut off from the internet and has lost power. This - caused an outage of a few hours yesterday (it happened when - I was out ice skating). + caused an outage of a few hours last saturday (it happened + when I was out ice skating, so I didn't notice it until I + got back).
I am now redirecting all American (north and south) traffic diff --git a/svelte/src/filesystem/FilesystemAPI.svelte b/svelte/src/filesystem/FilesystemAPI.svelte index d36100f..4e38c4e 100644 --- a/svelte/src/filesystem/FilesystemAPI.svelte +++ b/svelte/src/filesystem/FilesystemAPI.svelte @@ -1,5 +1,19 @@