mirror of
https://github.com/romancm/gamebrary
synced 2024-11-14 23:47:08 +00:00
use util to convert file sizes
This commit is contained in:
parent
0439cebdad
commit
fcaff34a81
1 changed files with 7 additions and 9 deletions
|
@ -21,7 +21,7 @@
|
|||
{{ wallpaper.name }}
|
||||
|
||||
<b-badge v-if="wallpaper.metadata && wallpaper.metadata.size">
|
||||
{{ bytesToSize(wallpaper.metadata.size) }}
|
||||
{{ formatSize(wallpaper) }}
|
||||
</b-badge>
|
||||
</h6>
|
||||
|
||||
|
@ -51,6 +51,7 @@
|
|||
|
||||
<script>
|
||||
import PreviewWallpaperModal from '@/components/Wallpapers/PreviewWallpaperModal';
|
||||
import { bytesToSize } from '@/utils';
|
||||
import { mapState } from 'vuex';
|
||||
|
||||
export default {
|
||||
|
@ -85,15 +86,12 @@ export default {
|
|||
}
|
||||
},
|
||||
|
||||
bytesToSize(bytes) {
|
||||
// TODO: put in util
|
||||
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
|
||||
formatSize(wallpaper) {
|
||||
const size = wallpaper && wallpaper.metadata && wallpaper.metadata.size
|
||||
? wallpaper.metadata.size
|
||||
: 0;
|
||||
|
||||
if (bytes === 0) return '0 Byte';
|
||||
|
||||
const i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)), 0);
|
||||
|
||||
return `${Math.round(bytes / (1024 ** i), 2)} ${sizes[i]}`;
|
||||
return bytesToSize(size);
|
||||
},
|
||||
|
||||
confirmDeleteWallpaper(file) {
|
||||
|
|
Loading…
Reference in a new issue