2019-08-09 20:20:08 +00:00
|
|
|
<template>
|
|
|
|
<span class="preview-size">({{ previewSize }})</span>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2019-11-16 17:24:03 +00:00
|
|
|
import constants from "../js/constants";
|
2019-08-09 20:20:08 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: "LinkPreviewFileSize",
|
|
|
|
props: {
|
|
|
|
size: Number,
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
previewSize() {
|
|
|
|
let size = this.size;
|
|
|
|
|
|
|
|
// Threshold for SI units
|
|
|
|
const thresh = 1024;
|
|
|
|
|
|
|
|
let u = 0;
|
|
|
|
|
|
|
|
do {
|
|
|
|
size /= thresh;
|
|
|
|
++u;
|
|
|
|
} while (size >= thresh && u < constants.sizeUnits.length - 1);
|
|
|
|
|
|
|
|
const displaySize = size.toFixed(1);
|
|
|
|
const unit = constants.sizeUnits[u];
|
|
|
|
|
|
|
|
return `${displaySize} ${unit}`;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|