@@ -13,21 +13,6 @@ export default function getLangCookie() {
13
13
return matches ? decodeURIComponent ( matches [ 1 ] ) : "en" ;
14
14
}
15
15
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
- }
31
16
32
17
function check_duplicate ( container , share , currentdetails ) {
33
18
for ( let detail of currentdetails ) {
@@ -163,64 +148,29 @@ export async function syncContainerACLs(store) {
163
148
}
164
149
165
150
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" ] ;
179
152
180
- const result = shiftSizeDivision ( [ byteval , count ] ) ;
181
- let ret = result [ 0 ] . toString ( ) ;
153
+ let size = val ;
154
+ let unitIndex = 0 ;
182
155
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
+ }
187
160
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 ( ) ;
199
163
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 ( "." , "," ) ;
220
166
}
221
- return ret ;
167
+
168
+ return `${ result } ${ BYTE_UNITS [ unitIndex ] } ` ;
222
169
}
223
170
171
+
172
+
173
+
224
174
export async function computeSHA256 ( keyContent ) {
225
175
const msgUint8 = new TextEncoder ( ) . encode ( keyContent ) ;
226
176
const hashBuffer = await crypto . subtle . digest ( "SHA-256" , msgUint8 ) ;
0 commit comments