Skip to content

Commit f4452f7

Browse files
author
Sampsa Penna
committed
size bigger than 1TB bug fixed (merge commit)
Merge branch '1249-bucket-sizes-show-unrealistic-wrong-sizes' into 'main' * size bigger than 1TB bug fixed Closes #1249 See merge request https://gitlab.ci.csc.fi/sds-dev/sd-connect/swift-browser-ui/-/merge_requests/395 Approved-by: Joonatan Mäkinen <[email protected]> Co-authored-by: Dean Ruina <[email protected]> Merged by Sampsa Penna <[email protected]>
2 parents 87a4a06 + 7557353 commit f4452f7

File tree

1 file changed

+16
-66
lines changed
  • swift_browser_ui_frontend/src/common

1 file changed

+16
-66
lines changed

swift_browser_ui_frontend/src/common/conv.js

+16-66
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,6 @@ export default function getLangCookie() {
1313
return matches ? decodeURIComponent(matches[1]) : "en";
1414
}
1515

16-
function shiftSizeDivision(vallist) {
17-
"use strict";
18-
// Javascript won't let us do anything but floating point division by
19-
// default, so a different approach was chosen anyway.
20-
// ( right shift by ten is a faster alias to division by 1024,
21-
// decimal file sizes are heresy and thus can't be enabled )
22-
switch (vallist[0] >>> 10) {
23-
case 0:
24-
return vallist;
25-
default:
26-
vallist[0] = vallist[0] >>> 10;
27-
vallist[1] = vallist[1] + 1;
28-
return shiftSizeDivision(vallist);
29-
}
30-
}
3116

3217
function check_duplicate(container, share, currentdetails) {
3318
for (let detail of currentdetails) {
@@ -163,64 +148,29 @@ export async function syncContainerACLs(store) {
163148
}
164149

165150
export function getHumanReadableSize(val, locale) {
166-
// Get a human readable version of the size, which is returned from the
167-
// API as bytes
168-
169-
const isLargeVal = val > 4294967296;
170-
let largeNum;
171-
let byteval = val;
172-
let count = 0;
173-
174-
if (isLargeVal) {
175-
largeNum = val / 1073741824;
176-
byteval = parseInt(largeNum);
177-
count = 3;
178-
}
151+
const BYTE_UNITS = ["B", "KiB", "MiB", "GiB", "TiB", "PiB"];
179152

180-
const result = shiftSizeDivision([byteval, count]);
181-
let ret = result[0].toString();
153+
let size = val;
154+
let unitIndex = 0;
182155

183-
if (ret.length === 1 && ret !== "0") {
184-
//display single digit results with one decimal rounded up
185-
let decimal;
186-
let retNum = result[0];
156+
while (size >= 1024 && unitIndex < BYTE_UNITS.length - 1) {
157+
size /= 1024;
158+
unitIndex++;
159+
}
187160

188-
for (let i=count; i < result[1]; i++) {
189-
retNum = retNum << 10;
190-
}
191-
if (isLargeVal) {
192-
decimal = largeNum - retNum;
193-
}
194-
else {
195-
let remainder = val ^ retNum;
196-
decimal = remainder / Math.pow(1024, result[1]);
197-
}
198-
ret = (result[0] + decimal).toFixed(1).toString();
161+
const decimalSize = size.toFixed(1);
162+
let result = decimalSize.toString();
199163

200-
if (locale === "fi") {
201-
ret = ret.replace(".", ",");
202-
}
203-
}
204-
switch (result[1]) {
205-
case 0:
206-
ret += " B";
207-
break;
208-
case 1:
209-
ret += " KiB";
210-
break;
211-
case 2:
212-
ret += " MiB";
213-
break;
214-
case 3:
215-
ret += " GiB";
216-
break;
217-
case 4:
218-
ret += " TiB";
219-
break;
164+
if (locale === "fi") {
165+
result = result.replace(".", ",");
220166
}
221-
return ret;
167+
168+
return `${result} ${BYTE_UNITS[unitIndex]}`;
222169
}
223170

171+
172+
173+
224174
export async function computeSHA256(keyContent) {
225175
const msgUint8 = new TextEncoder().encode(keyContent);
226176
const hashBuffer = await crypto.subtle.digest("SHA-256", msgUint8);

0 commit comments

Comments
 (0)