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

View File

@ -83,7 +83,7 @@
import { mapActions, mapState } from "pinia"; import { mapActions, mapState } from "pinia";
import { useFileStore } from "@/stores/file"; import { useFileStore } from "@/stores/file";
import { useLayoutStore } from "@/stores/layout"; import { useLayoutStore } from "@/stores/layout";
import { filesize } from "filesize"; import { filesize } from "@/utils";
import dayjs from "dayjs"; import dayjs from "dayjs";
import { files as api } from "@/api"; import { files as api } from "@/api";
@ -99,7 +99,7 @@ export default {
]), ]),
humanSize: function () { humanSize: function () {
if (this.selectedCount === 0 || !this.isListing) { if (this.selectedCount === 0 || !this.isListing) {
return filesize(this.req.size, { base: 2 }); return filesize(this.req.size);
} }
let sum = 0; let sum = 0;
@ -108,7 +108,7 @@ export default {
sum += this.req.items[selected].size; sum += this.req.items[selected].size;
} }
return filesize(sum, { base: 2 }); return filesize(sum);
}, },
humanTime: function () { humanTime: function () {
if (this.selectedCount === 0) { 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"> <script setup lang="ts">
import { pub as api } from "@/api"; import { pub as api } from "@/api";
import { filesize } from "filesize"; import { filesize } from "@/utils";
import dayjs from "dayjs"; import dayjs from "dayjs";
import { Base64 } from "js-base64"; import { Base64 } from "js-base64";
@ -241,7 +241,7 @@ const humanSize = computed(() => {
if (req.value) { if (req.value) {
return req.value.isDir return req.value.isDir
? req.value.items.length ? req.value.items.length
: filesize(req.value.size ?? 0, { base: 2 }); : filesize(req.value.size ?? 0);
} else { } else {
return ""; return "";
} }