From 4acf4fddf65302ca2b1bd05c631eb27cf7123d65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=A1clav=20Val=C3=AD=C4=8Dek=20=28YCNet=29?= Date: Wed, 16 May 2018 20:55:38 +0200 Subject: [PATCH] Show artifacts sizes in webui --- src/laminar.cpp | 1 + src/resources/index.html | 2 +- src/resources/js/app.js | 31 +++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/laminar.cpp b/src/laminar.cpp index 4aa3ae6..aec1950 100644 --- a/src/laminar.cpp +++ b/src/laminar.cpp @@ -133,6 +133,7 @@ void Laminar::populateArtifacts(Json &j, std::string job, uint num) const { j.StartObject(); j.set("url", archiveUrl + it->path().string().substr(prefixLen)); j.set("filename", it->path().string().substr(scopeLen+1)); + j.set("size", fs::file_size(it->path())); j.EndObject(); } } diff --git a/src/resources/index.html b/src/resources/index.html index ad3134e..a209793 100644 --- a/src/resources/index.html +++ b/src/resources/index.html @@ -222,7 +222,7 @@
Artifacts
diff --git a/src/resources/js/app.js b/src/resources/js/app.js index a9a7da4..2e7add4 100644 --- a/src/resources/js/app.js +++ b/src/resources/js/app.js @@ -2,6 +2,37 @@ * frontend application for Laminar Continuous Integration * https://laminar.ohwg.net */ + +;;; +// usage: {{ file.size | prettyBytes }} +// source: https://gist.github.com/james2doyle/4aba55c22f084800c199 +Vue.filter('prettyBytes', function (num) { + // jacked from: https://github.com/sindresorhus/pretty-bytes + if (typeof num !== 'number' || isNaN(num)) { + throw new TypeError('Expected a number'); + } + + var exponent; + var unit; + var neg = num < 0; + var units = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; + + if (neg) { + num = -num; + } + + if (num < 1) { + return (neg ? '-' : '') + num + ' B'; + } + + exponent = Math.min(Math.floor(Math.log(num) / Math.log(1000)), units.length - 1); + num = (num / Math.pow(1000, exponent)).toFixed(2) * 1; + unit = units[exponent]; + + return (neg ? '-' : '') + num + ' ' + unit; +}); + + const wsp = function(path) { return new WebSocket((location.protocol === 'https:'?'wss://':'ws://') + location.host + path);