From b87909c9dd7aabe7b8f8bd63138876dff5cd2200 Mon Sep 17 00:00:00 2001 From: cbdev Date: Fri, 29 Oct 2021 20:22:18 +0200 Subject: Implement gallery view, add noscript notice, implement rudimentary overwrite protection --- assets/502.html | 1 + assets/cargohold.css | 10 ++++++++++ assets/cargohold.js | 29 +++++++++++++++++++++++++++-- 3 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 assets/502.html (limited to 'assets') diff --git a/assets/502.html b/assets/502.html new file mode 100644 index 0000000..1bc0ca4 --- /dev/null +++ b/assets/502.html @@ -0,0 +1 @@ +FIXME: Do a proper error page diff --git a/assets/cargohold.css b/assets/cargohold.css index bec6b3a..747b916 100644 --- a/assets/cargohold.css +++ b/assets/cargohold.css @@ -9,6 +9,16 @@ html { background-color: #425; } +.listing-entry > img { + display: inline-block; + width: 100%; +} + +#noscript-warning { + padding: 1em; + font-size: 110%; +} + .listing-entry, .listing-entry:visited { display: block; text-decoration: none; diff --git a/assets/cargohold.js b/assets/cargohold.js index 2ba8cc0..18dbeae 100644 --- a/assets/cargohold.js +++ b/assets/cargohold.js @@ -45,6 +45,10 @@ function queue_work(){ }; req.onreadystatechange = function(evt){ console.log("Upload for " + item.file.name + " state " + req.readyState); + if(req.readyState === XMLHttpRequest.DONE && req.status != 200){ + console.log("Upload for " + item.file.name + " failed with " + req.status); + item.node.className += " errored"; + } }; req.open("POST", 'upload'); req.send(data); @@ -100,9 +104,28 @@ function listing_clear(){ element("dirlisting").innerHTML = ""; } -function listing_add(file){ +function interface_update(access){ + if(!access.includes("c")){ + element("tab-upload-label").style.display = "none"; + } + + if(!access.includes("r")){ + element("tab-view-label").style.display = "none"; + element("tab-upload").checked = "checked"; + } +} + +function listing_add(file, style = "default"){ let link = node("a", "listing-entry", file.name); link.href = "file/" + encodeURIComponent(file.name); + + if(style == "gallery"){ + let image = node("img", "preview"); + image.src = "preview/" + encodeURIComponent(file.name); + //link.insertBefore(image, link.firstChild); + link.appendChild(image); + } + element("dirlisting").appendChild(link); } @@ -111,8 +134,10 @@ function listing_update(){ let req = new XMLHttpRequest(); req.onload = function(evt){ let data = JSON.parse(req.response); + interface_update(data.access); + for(let i = 0; i < data.files.length; i++){ - listing_add(data.files[i]); + listing_add(data.files[i], data.display); } }; req.open("GET", "listing"); -- cgit v1.2.3