Simplify filesize calls

This commit is contained in:
Kloon ImKloon 2023-10-06 20:36:09 +02:00
parent 28a724e793
commit 2df99e0d8c
No known key found for this signature in database
GPG Key ID: CCF1C86A995C5B6A
4 changed files with 13 additions and 10 deletions

View File

@ -41,7 +41,7 @@ import { useFileStore } from "@/stores/file";
import { useLayoutStore } from "@/stores/layout";
import { enableThumbs } from "@/utils/constants";
import { filesize } from "filesize";
import { filesize } from "@/utils";
import dayjs from "dayjs";
import { files as api } from "@/api";
import * as upload from "@/utils/upload";
@ -105,9 +105,7 @@ export default {
...mapActions(useFileStore, ["removeSelected"]),
...mapActions(useLayoutStore, ["showHover", "closeHovers"]),
humanSize: function () {
return this.type == "invalid_link"
? "invalid link"
: filesize(this.size, { base: 2 });
return this.type == "invalid_link" ? "invalid link" : filesize(this.size);
},
humanTime: function () {
if (this.readOnly == undefined && this.user.dateFormat) {

View File

@ -83,7 +83,7 @@
import { mapActions, mapState } from "pinia";
import { useFileStore } from "@/stores/file";
import { useLayoutStore } from "@/stores/layout";
import { filesize } from "filesize";
import { filesize } from "@/utils";
import dayjs from "dayjs";
import { files as api } from "@/api";
@ -99,7 +99,7 @@ export default {
]),
humanSize: function () {
if (this.selectedCount === 0 || !this.isListing) {
return filesize(this.req.size, { base: 2 });
return filesize(this.req.size);
}
let sum = 0;
@ -108,7 +108,7 @@ export default {
sum += this.req.items[selected].size;
}
return filesize(sum, { base: 2 });
return filesize(sum);
},
humanTime: function () {
if (this.selectedCount === 0) {

View File

@ -1 +1,6 @@
// export * from "./funcs";
import { partial } from "filesize";
/**
* Formats filesize as KiB/MiB/...
*/
export const filesize = partial({ base: 2 });

View File

@ -181,7 +181,7 @@
<script setup lang="ts">
import { pub as api } from "@/api";
import { filesize } from "filesize";
import { filesize } from "@/utils";
import dayjs from "dayjs";
import { Base64 } from "js-base64";
@ -241,7 +241,7 @@ const humanSize = computed(() => {
if (req.value) {
return req.value.isDir
? req.value.items.length
: filesize(req.value.size ?? 0, { base: 2 });
: filesize(req.value.size ?? 0);
} else {
return "";
}