2019-11-24 14:16:24 +01:00
|
|
|
import AbstractModel from './abstractModel'
|
|
|
|
|
|
|
|
export default class FileModel extends AbstractModel {
|
2020-02-08 14:16:06 +01:00
|
|
|
constructor(data) {
|
|
|
|
super(data)
|
|
|
|
this.created = new Date(this.created)
|
|
|
|
}
|
|
|
|
|
2019-11-24 14:16:24 +01:00
|
|
|
defaults() {
|
|
|
|
return {
|
|
|
|
id: 0,
|
|
|
|
mime: '',
|
|
|
|
name: '',
|
|
|
|
size: '',
|
2020-02-08 14:16:06 +01:00
|
|
|
created: null,
|
2019-11-24 14:16:24 +01: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]
|
|
|
|
}
|
|
|
|
}
|