This repository has been archived on 2024-02-08. You can view files and clone it, but cannot push or open issues or pull requests.
frontend/src/models/file.ts

44 lines
693 B
TypeScript
Raw Normal View History

import AbstractModel, { type IAbstract } from './abstractModel'
2019-11-24 13:16:24 +00:00
export interface IFile extends IAbstract {
2022-06-23 01:22:21 +00:00
id: number
mime: string
name: string
size: number
created: Date
2022-07-20 22:42:36 +00:00
}
export default class FileModel extends AbstractModel implements IFile {
id = 0
mime = ''
name = ''
size = 0
created: Date = null
2022-06-23 01:22:21 +00:00
constructor(data: Partial<IFile>) {
super()
this.assignData(data)
this.created = new Date(this.created)
2019-11-24 13:16:24 +00:00
}
getHumanSize() {
const sizes = {
0: 'B',
1: 'KB',
2: 'MB',
3: 'GB',
4: 'TB',
}
let it = 0
let size = this.size
while (size > 1024) {
size /= 1024
it++
}
return Number(Math.round(size + 'e2') + 'e-2') + ' ' + sizes[it]
2019-11-24 13:16:24 +00:00
}
}