diff --git a/res/include/script/dependencies/util.js b/res/include/script/dependencies/util.js index ef227ec..9beb7f3 100644 --- a/res/include/script/dependencies/util.js +++ b/res/include/script/dependencies/util.js @@ -90,3 +90,17 @@ function domainURL() { } return url; } + +function formatDataVolume(amt = 0, precision = 3) { + if (precision < 3) { precision = 3; } + if (amt >= 1e12) { + return (amt/1e12).toPrecision(precision) + " TB"; + } else if (amt >= 1e9) { + return (amt/1e9).toPrecision(precision) + " GB"; + } else if (amt >= 1e6) { + return (amt/1e6).toPrecision(precision) + " MB"; + } else if (amt >= 1e3) { + return (amt/1e3).toPrecision(precision) + " kB"; + } + return amt + " B" +} diff --git a/res/include/script/file_viewer/DetailsWindow.js b/res/include/script/file_viewer/DetailsWindow.js index c31de32..a412f41 100644 --- a/res/include/script/file_viewer/DetailsWindow.js +++ b/res/include/script/file_viewer/DetailsWindow.js @@ -56,13 +56,12 @@ class DetailsWindow { + "URL"+domainURL()+"/u/" + file.id + "" + "Mime Type" + escapeHTML(file.mime_type) + "" + "ID" + file.id + "" - + "Size" + formatDataVolume(file.size) + "" - + "Bandwidth" + formatDataVolume(file.bandwidth_used) + "" + + "Size" + formatDataVolume(file.size, 4) + "" + + "Bandwidth" + formatDataVolume(file.bandwidth_used, 4) + "" + "Upload Date" + file.date_upload + "" + "Description" + escapeHTML(desc) + "" + ""; - dw.viewer.toolbar.setStats(file.views, file.bandwidth_used/file.size); if(dw.visible) { dw.updateGraph(file.id); } diff --git a/res/include/script/file_viewer/Toolbar.js b/res/include/script/file_viewer/Toolbar.js index 449805b..6b8bb83 100644 --- a/res/include/script/file_viewer/Toolbar.js +++ b/res/include/script/file_viewer/Toolbar.js @@ -7,10 +7,11 @@ class Toolbar { // Elements divToolbar = null; divFilePreview = null; - downloadFrame = null + downloadFrame = null; spanViews = null; spanDownloads = null; + spanSize = null; btnToggleToolbar = null; btnDownload = null; @@ -27,6 +28,7 @@ class Toolbar { t.downloadFrame = document.getElementById("download_frame"); t.spanViews = document.getElementById("stat_views"); t.spanDownloads = document.getElementById("stat_downloads"); + t.spanSize = document.getElementById("stat_size"); t.btnToggleToolbar = document.getElementById("btn_toggle_toolbar"); t.btnDownload = document.getElementById("btn_download"); @@ -148,9 +150,10 @@ class Toolbar { }, 60000); } - setStats(views, downloads) {let t = this; - t.spanViews.innerText = views - t.spanDownloads.innerText = Math.round(downloads*10)/10; + setStats(file) {let t = this; + t.spanViews.innerText = file.views + t.spanDownloads.innerText = Math.round((file.bandwidth_used/file.size)*10)/10; + t.spanSize.innerText = formatDataVolume(file.size, 3); } } @@ -171,16 +174,3 @@ function loadCaptcha(){ } }); } - -function formatDataVolume(amt) { - if (amt > 1e12) { - return Math.round(amt/1e9)/1e3 + " TB"; - } else if (amt > 1e9) { - return Math.round(amt/1e6)/1e3 + " GB"; - } else if (amt > 1e6) { - return Math.round(amt/1e3)/1e3 + " MB"; - } else if (amt > 1e3) { - return Math.round(amt)/1e3 + " kB"; - } - return amt + " B" -} diff --git a/res/include/script/file_viewer/Viewer.js b/res/include/script/file_viewer/Viewer.js index 7a9196a..c589faa 100644 --- a/res/include/script/file_viewer/Viewer.js +++ b/res/include/script/file_viewer/Viewer.js @@ -73,6 +73,7 @@ class Viewer { // Update the file details v.detailsWindow.setDetails(file); + v.toolbar.setStats(file); // Register a new view. We don't care what this returns becasue we can't // do anything about it anyway diff --git a/res/include/style/layout.css b/res/include/style/layout.css index d89a543..049b76d 100644 --- a/res/include/style/layout.css +++ b/res/include/style/layout.css @@ -275,7 +275,8 @@ table:not(.form) {border-collapse: collapse; width: 100%;} tr:not(.form) {border-bottom: 1px var(--layer_2_color_border) solid;} tr > td {padding: 0.3em;} @media(max-width: 30em) { - tr > td { + /* Forms will be stacked on small screens */ + tr.form > td { box-sizing: border-box; float: left; width: 100%; diff --git a/res/template/admin.html b/res/template/admin.html index f5a05b2..0b0531b 100644 --- a/res/template/admin.html +++ b/res/template/admin.html @@ -29,6 +29,8 @@