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.js

38 lines
540 B
JavaScript

import AbstractModel from './abstractModel'
export default class FileModel extends AbstractModel {
constructor(data) {
super(data)
this.created = new Date(this.created)
}
defaults() {
return {
id: 0,
mime: '',
name: '',
size: '',
created: null,
}
}
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]
}
}