π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
fix(gallery):preserve-tb-storage-precision
Aswin Asokcbb57d072ca4
diff --git a/desktop/changes/storage-rounding.md b/desktop/changes/storage-rounding.mdnew file mode 100644index 0000000000..8edb6a6f96--- /dev/null+++ b/desktop/changes/storage-rounding.md@@ -0,0 +1 @@+- Fixed TB storage usage rounding.diff --git a/web/apps/photos/tests/storage-units.test.ts b/web/apps/photos/tests/storage-units.test.tsnew file mode 100644index 0000000000..7af538b3b2--- /dev/null+++ b/web/apps/photos/tests/storage-units.test.ts@@ -0,0 +1,19 @@+import { formattedStorageByteSize } from "ente-gallery/utils/units";+import { expect, test, vi } from "vitest";++vi.mock("i18next", () => ({+ t: (key: string) => key.replace("storage_unit.", "").toUpperCase(),+}));++test("TB usage retains precision alongside the quota and free space", () => {+ const gb = 1024 ** 3;+ const storage = 2 * 1024 ** 4;+ const usage = storage - 902 * gb;++ expect(formattedStorageByteSize(usage, { round: true })).toBe("1.1 TB");+ expect(formattedStorageByteSize(usage)).toBe("1.1 TB");+ expect(formattedStorageByteSize(storage)).toBe("2 TB");+ expect(formattedStorageByteSize(storage - usage)).toBe("902 GB");+ expect(formattedStorageByteSize(10.2 * gb, { round: true })).toBe("11 GB");+ expect(formattedStorageByteSize(10.2 * gb)).toBe("10 GB");+});diff --git a/web/packages/gallery/utils/units.ts b/web/packages/gallery/utils/units.tsindex 8dae6b847b..93f2955b4e 100644--- a/web/packages/gallery/utils/units.ts+++ b/web/packages/gallery/utils/units.ts@@ -44,8 +44,8 @@ export const formattedStorageByteSize = (quantity = Number(quantity.toFixed(1));- // Storage displays above 10 GB omit fractional precision.- if (bytes >= 10 * 1024 * 1024 * 1024) {+ // Keep fractional TB values so usage does not look like a full quota.+ if (bytes >= 10 * 1024 * 1024 * 1024 && unit != "tb") {if (options?.round) {quantity = Math.ceil(quantity);} else {