aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-06-23 10:45:28 +0200
committerChocobozzz <me@florianbigard.com>2022-06-23 10:45:36 +0200
commit408fd5e424475be0e21d207d518ea9cb7aa57c1d (patch)
treeca682e1eeaa18d3d3651750d2c4232809393545b /client/src
parent20886f4bf968dd23b50f66137b1aaac06cb8edfb (diff)
downloadPeerTube-408fd5e424475be0e21d207d518ea9cb7aa57c1d.tar.gz
PeerTube-408fd5e424475be0e21d207d518ea9cb7aa57c1d.tar.zst
PeerTube-408fd5e424475be0e21d207d518ea9cb7aa57c1d.zip
More precise format byte with GB
Diffstat (limited to 'client/src')
-rw-r--r--client/src/assets/player/shared/common/utils.ts14
1 files changed, 6 insertions, 8 deletions
diff --git a/client/src/assets/player/shared/common/utils.ts b/client/src/assets/player/shared/common/utils.ts
index da7dda0c7..a010d9184 100644
--- a/client/src/assets/player/shared/common/utils.ts
+++ b/client/src/assets/player/shared/common/utils.ts
@@ -4,17 +4,15 @@ function toTitleCase (str: string) {
4 return str.charAt(0).toUpperCase() + str.slice(1) 4 return str.charAt(0).toUpperCase() + str.slice(1)
5} 5}
6 6
7// https://github.com/danrevah/ngx-pipes/blob/master/src/pipes/math/bytes.ts 7const dictionaryBytes = [
8// Don't import all Angular stuff, just copy the code with shame 8 { max: 1024, type: 'B', decimals: 0 },
9const dictionaryBytes: Array<{max: number, type: string}> = [ 9 { max: 1048576, type: 'KB', decimals: 0 },
10 { max: 1024, type: 'B' }, 10 { max: 1073741824, type: 'MB', decimals: 0 },
11 { max: 1048576, type: 'KB' }, 11 { max: 1.0995116e12, type: 'GB', decimals: 1 }
12 { max: 1073741824, type: 'MB' },
13 { max: 1.0995116e12, type: 'GB' }
14] 12]
15function bytes (value: number) { 13function bytes (value: number) {
16 const format = dictionaryBytes.find(d => value < d.max) || dictionaryBytes[dictionaryBytes.length - 1] 14 const format = dictionaryBytes.find(d => value < d.max) || dictionaryBytes[dictionaryBytes.length - 1]
17 const calc = Math.floor(value / (format.max / 1024)).toString() 15 const calc = (value / (format.max / 1024)).toFixed(format.decimals)
18 16
19 return [ calc, format.type ] 17 return [ calc, format.type ]
20} 18}