Skip to content
This repository was archived by the owner on Apr 5, 2024. It is now read-only.

Commit 9b92b10

Browse files
committed
Added Size
1 parent 24700d0 commit 9b92b10

File tree

4 files changed

+25
-13
lines changed

4 files changed

+25
-13
lines changed

webapp_frontend/src/background/api/filesystem.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const exampleValue = (path: string): BackendFolderContentsData => {
1414
{
1515
"createdByUserId": 0,
1616
"id": 0,
17-
"lastUpdated": 0,
17+
"lastUpdated": 153354,
1818
"name": "inBLA",
1919
"permissionSet": {
2020
"editableForGroups": [
@@ -42,7 +42,7 @@ const exampleValue = (path: string): BackendFolderContentsData => {
4242
}
4343
]
4444
},
45-
"size": 0,
45+
"size": 546,
4646
"type": "file"
4747
},
4848
{
@@ -110,7 +110,7 @@ const exampleValue = (path: string): BackendFolderContentsData => {
110110
}
111111
]
112112
},
113-
"size": 2756,
113+
"size": 27565846,
114114
"type": "file"
115115
},
116116
{
@@ -144,7 +144,7 @@ const exampleValue = (path: string): BackendFolderContentsData => {
144144
}
145145
]
146146
},
147-
"size": 22486,
147+
"size": 224850446,
148148
"type": "file"
149149
},
150150
{
@@ -178,7 +178,7 @@ const exampleValue = (path: string): BackendFolderContentsData => {
178178
}
179179
]
180180
},
181-
"size": 486,
181+
"size": 4866848,
182182
"type": "file"
183183
},
184184
{
@@ -212,7 +212,7 @@ const exampleValue = (path: string): BackendFolderContentsData => {
212212
}
213213
]
214214
},
215-
"size": 96,
215+
"size": 96643,
216216
"type": "file"
217217
},
218218
{
@@ -246,7 +246,7 @@ const exampleValue = (path: string): BackendFolderContentsData => {
246246
}
247247
]
248248
},
249-
"size": 86,
249+
"size": 861858,
250250
"type": "file"
251251
}
252252
],
@@ -282,7 +282,7 @@ const exampleValue = (path: string): BackendFolderContentsData => {
282282
}
283283
]
284284
},
285-
"size": 0,
285+
"size": 18975576,
286286
"type": "FOLDER"
287287
}]
288288
}
@@ -319,7 +319,7 @@ const exampleValue = (path: string): BackendFolderContentsData => {
319319
}
320320
]
321321
},
322-
"size": 0,
322+
"size": 5489,
323323
"type": "file"
324324
}
325325
],
@@ -361,7 +361,7 @@ const exampleFileSystem = {
361361
}
362362
]
363363
},
364-
"size": 0,
364+
"size": 13,
365365
"type": "FOLDER"
366366
}
367367
],
@@ -398,7 +398,7 @@ const exampleFileSystem = {
398398
}
399399
]
400400
},
401-
"size": 0,
401+
"size": 864070843,
402402
"type": "FOLDER"
403403
},
404404
{
@@ -433,7 +433,7 @@ const exampleFileSystem = {
433433
}
434434
]
435435
},
436-
"size": 0,
436+
"size": 1684035,
437437
"type": "FOLDER"
438438
}
439439
]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export function formatBytes(bytes:number, decimals:number = 2):string {
2+
if (bytes === 0) return '0 Bytes';
3+
4+
const k:number = 1024;
5+
const dm:number = decimals < 0 ? 0 : decimals;
6+
const sizes:string[] = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
7+
8+
const i:number = Math.floor(Math.log(bytes) / Math.log(k));
9+
10+
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
11+
}
File renamed without changes.

webapp_frontend/src/components/pages/filesytem/FileListItem.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
} from "../../../elements/svg/SymbolFile";
1111
import {reverseString} from "../../../background/methods/strings";
1212
import {getDateAsStringFromTimestamp} from "../../../background/methods/time";
13+
import {formatBytes} from "../../../background/methods/bytes";
1314

1415
type Props = {
1516
fileListItem: FileListEntity;
@@ -78,7 +79,7 @@ export default function FileListItem(props: Props): ReactElement {
7879
onClick={() => onClick()}>{props.fileListItem.name}</Link></Col>
7980
<Col xs={3}>{props.fileListItem.createdByUserId}</Col>
8081
<Col xs={1}>{getDateAsStringFromTimestamp(props.fileListItem.lastUpdated)}</Col>
81-
<Col xs={1}>{props.fileListItem.size}</Col>
82+
<Col xs={1}>{formatBytes(props.fileListItem.size)}</Col>
8283
</>
8384
)
8485
}

0 commit comments

Comments
 (0)