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
|
// TODO BETTER SORT FOR MULTPLE SIZE OR CUSTOM PIPE TO kB to MB / GB
|
||||||
title: 'Size',
|
title: 'Size',
|
||||||
dataIndex: 'size',
|
dataIndex: 'sizedisp',
|
||||||
className: 'column-size',
|
className: 'column-size',
|
||||||
responsive: ['lg'],
|
responsive: ['lg'],
|
||||||
sortDirections: ['ascend', 'descend'],
|
sortDirections: ['ascend', 'descend'],
|
||||||
|
|
|
@ -12,6 +12,7 @@ type BaseDocument = {
|
||||||
export type FolderDocument = BaseDocument & {
|
export type FolderDocument = BaseDocument & {
|
||||||
type: 'folder' | 'folder-file';
|
type: 'folder' | 'folder-file';
|
||||||
size: number;
|
size: number;
|
||||||
|
sizedisp: string;
|
||||||
mtime: number;
|
mtime: number;
|
||||||
modified: string;
|
modified: string;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import type { Document, FolderDocument } from '@/repositories/Document';
|
import type { Document, FolderDocument } from '@/repositories/Document';
|
||||||
import type { ISimpleError } from '@/repositories/Client';
|
import type { ISimpleError } from '@/repositories/Client';
|
||||||
import { fetchFile } from '@/repositories/Document'
|
import { fetchFile } from '@/repositories/Document'
|
||||||
import { formatUnixDate } from '@/utils';
|
import { formatSize, formatUnixDate } from '@/utils';
|
||||||
import { defineStore } from 'pinia';
|
import { defineStore } from 'pinia';
|
||||||
|
|
||||||
|
|
||||||
|
@ -60,6 +60,7 @@ export const useDocumentStore = defineStore({
|
||||||
name,
|
name,
|
||||||
key: id,
|
key: id,
|
||||||
size,
|
size,
|
||||||
|
sizedisp: formatSize(size),
|
||||||
mtime,
|
mtime,
|
||||||
modified: formatUnixDate(mtime),
|
modified: formatUnixDate(mtime),
|
||||||
type: dir === undefined ? 'folder-file' : 'folder',
|
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) {
|
export function formatUnixDate(t: number) {
|
||||||
const date = new Date(t * 1000)
|
const date = new Date(t * 1000)
|
||||||
const now = new Date()
|
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">
|
<link rel="icon" href="/favicon.ico">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||||
<title>Vite Vasanko</title>
|
<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">
|
<link rel="stylesheet" href="/assets/index-ee545ab1.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user