Human-readable sizes
This commit is contained in:
parent
0d186726b5
commit
8cc3ed1a04
|
@ -112,7 +112,7 @@
|
|||
{
|
||||
// TODO BETTER SORT FOR MULTPLE SIZE OR CUSTOM PIPE TO kB to MB / GB
|
||||
title: 'Size',
|
||||
dataIndex: 'size',
|
||||
dataIndex: 'sizedisp',
|
||||
className: 'column-size',
|
||||
responsive: ['lg'],
|
||||
sortDirections: ['ascend', 'descend'],
|
||||
|
|
|
@ -12,6 +12,7 @@ type BaseDocument = {
|
|||
export type FolderDocument = BaseDocument & {
|
||||
type: 'folder' | 'folder-file';
|
||||
size: number;
|
||||
sizedisp: string;
|
||||
mtime: number;
|
||||
modified: string;
|
||||
};
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import type { Document, FolderDocument } from '@/repositories/Document';
|
||||
import type { ISimpleError } from '@/repositories/Client';
|
||||
import { fetchFile } from '@/repositories/Document'
|
||||
import { formatUnixDate } from '@/utils';
|
||||
import { formatSize, formatUnixDate } from '@/utils';
|
||||
import { defineStore } from 'pinia';
|
||||
|
||||
|
||||
|
@ -60,6 +60,7 @@ export const useDocumentStore = defineStore({
|
|||
name,
|
||||
key: id,
|
||||
size,
|
||||
sizedisp: formatSize(size),
|
||||
mtime,
|
||||
modified: formatUnixDate(mtime),
|
||||
type: dir === undefined ? 'folder-file' : 'folder',
|
||||
|
|
|
@ -6,6 +6,14 @@ export function determineFileType(inputString: string): "file" | "folder" {
|
|||
}
|
||||
}
|
||||
|
||||
export function formatSize(size: number) {
|
||||
for (const unit of [null, 'kB', 'MB', 'GB', 'TB', 'PB', 'EB']) {
|
||||
if (size < 1e5) return size.toLocaleString().replace(',', '\u202F') + (unit ? `\u202F${unit}` : '')
|
||||
size = Math.round(size / 1000)
|
||||
}
|
||||
return "huge"
|
||||
}
|
||||
|
||||
export function formatUnixDate(t: number) {
|
||||
const date = new Date(t * 1000)
|
||||
const now = new Date()
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -5,7 +5,7 @@
|
|||
<link rel="icon" href="/favicon.ico">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<title>Vite Vasanko</title>
|
||||
<script type="module" crossorigin src="/assets/index-dfc6f58a.js"></script>
|
||||
<script type="module" crossorigin src="/assets/index-10851222.js"></script>
|
||||
<link rel="stylesheet" href="/assets/index-ee545ab1.css">
|
||||
</head>
|
||||
<body>
|
||||
|
|
Loading…
Reference in New Issue
Block a user