- Swiss 极简、中文文案、无 emoji、内联 SVG 图标、浅色/深色变量 - admin:口令登录、账号列表与用量、新建(弹连接信息)、复制、换口令、只读/停用、删除 - client:账号登录、面包屑、上传(点击+拖拽)、下载、新建文件夹、重命名、删除 - Makefile:build/run/test/clean;accounts.example.json 示例配置
29 lines
869 B
TypeScript
29 lines
869 B
TypeScript
export function formatSize(bytes: number): string {
|
|
if (bytes < 1024) return `${bytes} B`
|
|
const units = ['KB', 'MB', 'GB', 'TB']
|
|
let value = bytes / 1024
|
|
let i = 0
|
|
while (value >= 1024 && i < units.length - 1) {
|
|
value /= 1024
|
|
i++
|
|
}
|
|
return `${value.toFixed(value >= 10 ? 0 : 1)} ${units[i]}`
|
|
}
|
|
|
|
export function formatTime(ms: number): string {
|
|
if (!ms) return '—'
|
|
const d = new Date(ms)
|
|
const pad = (n: number) => String(n).padStart(2, '0')
|
|
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}`
|
|
}
|
|
|
|
export function joinPath(dir: string, name: string): string {
|
|
return dir === '/' ? `/${name}` : `${dir}/${name}`
|
|
}
|
|
|
|
export function parentPath(p: string): string {
|
|
if (p === '/' || p === '') return '/'
|
|
const i = p.lastIndexOf('/')
|
|
return i <= 0 ? '/' : p.slice(0, i)
|
|
}
|