diff --git a/web/apps/photos/src/components/PhotoList/dedupe.tsx b/web/apps/photos/src/components/PhotoList/dedupe.tsx
index ab7badf1f..be412ad78 100644
--- a/web/apps/photos/src/components/PhotoList/dedupe.tsx
+++ b/web/apps/photos/src/components/PhotoList/dedupe.tsx
@@ -19,7 +19,7 @@ import {
} from "react-window";
import { Duplicate } from "services/deduplicationService";
import { EnteFile } from "types/file";
-import { convertBytesToHumanReadable } from "utils/file";
+import { convertBytesToHumanReadable } from "utils/units";
export enum ITEM_TYPE {
TIME = "TIME",
diff --git a/web/apps/photos/src/components/PhotoList/index.tsx b/web/apps/photos/src/components/PhotoList/index.tsx
index 4803995d4..508e9eab5 100644
--- a/web/apps/photos/src/components/PhotoList/index.tsx
+++ b/web/apps/photos/src/components/PhotoList/index.tsx
@@ -22,9 +22,9 @@ import {
areEqual,
} from "react-window";
import { EnteFile } from "types/file";
-import { convertBytesToHumanReadable } from "utils/file";
import { handleSelectCreator } from "utils/photoFrame";
import { PublicCollectionGalleryContext } from "utils/publicCollectionGallery";
+import { convertBytesToHumanReadable } from "utils/units";
const A_DAY = 24 * 60 * 60 * 1000;
const FOOTER_HEIGHT = 90;
diff --git a/web/apps/photos/src/components/Sidebar/SubscriptionCard/contentOverlay/storageSection.tsx b/web/apps/photos/src/components/Sidebar/SubscriptionCard/contentOverlay/storageSection.tsx
index 8ef5bea5e..90705753b 100644
--- a/web/apps/photos/src/components/Sidebar/SubscriptionCard/contentOverlay/storageSection.tsx
+++ b/web/apps/photos/src/components/Sidebar/SubscriptionCard/contentOverlay/storageSection.tsx
@@ -1,6 +1,6 @@
import { Box, styled, Typography } from "@mui/material";
import { t } from "i18next";
-import { convertBytesToGBs, makeHumanReadableStorage } from "utils/units";
+import { bytesInGB, makeHumanReadableStorage } from "utils/units";
const MobileSmallBox = styled(Box)`
display: none;
@@ -40,9 +40,7 @@ export default function StorageSection({ usage, storage }: Iprops) {
fontWeight={"bold"}
sx={{ fontSize: "24px", lineHeight: "30px" }}
>
- {`${convertBytesToGBs(usage)} / ${convertBytesToGBs(
- storage,
- )} ${t("GB")} ${t("USED")}`}
+ {`${bytesInGB(usage)} / ${bytesInGB(storage)} ${t("GB")} ${t("USED")}`}
diff --git a/web/apps/photos/src/components/pages/gallery/PlanSelector/card/paid.tsx b/web/apps/photos/src/components/pages/gallery/PlanSelector/card/paid.tsx
index 4ef76a491..0ef4b1594 100644
--- a/web/apps/photos/src/components/pages/gallery/PlanSelector/card/paid.tsx
+++ b/web/apps/photos/src/components/pages/gallery/PlanSelector/card/paid.tsx
@@ -5,11 +5,8 @@ import Box from "@mui/material/Box";
import Typography from "@mui/material/Typography";
import { t } from "i18next";
import { Trans } from "react-i18next";
-import {
- convertBytesToGBs,
- hasAddOnBonus,
- isSubscriptionCancelled,
-} from "utils/billing";
+import { hasAddOnBonus, isSubscriptionCancelled } from "utils/billing";
+import { bytesInGB } from "utils/units";
import { ManageSubscription } from "../manageSubscription";
import { PeriodToggler } from "../periodToggler";
import Plans from "../plans";
@@ -35,8 +32,7 @@ export default function PaidSubscriptionPlanSelectorCard({
{t("SUBSCRIPTION")}
- {convertBytesToGBs(subscription.storage, 2)}{" "}
- {t("GB")}
+ {bytesInGB(subscription.storage, 2)} {t("GB")}
@@ -50,7 +46,7 @@ export default function PaidSubscriptionPlanSelectorCard({
diff --git a/web/apps/photos/src/components/pages/gallery/PlanSelector/plans/planRow.tsx b/web/apps/photos/src/components/pages/gallery/PlanSelector/plans/planRow.tsx
index ca01b40b3..bb2347ddc 100644
--- a/web/apps/photos/src/components/pages/gallery/PlanSelector/plans/planRow.tsx
+++ b/web/apps/photos/src/components/pages/gallery/PlanSelector/plans/planRow.tsx
@@ -7,7 +7,7 @@ import { PLAN_PERIOD } from "constants/gallery";
import { t } from "i18next";
import { Plan, Subscription } from "types/billing";
import { hasPaidSubscription, isUserSubscribedPlan } from "utils/billing";
-import { convertBytesToGBs } from "utils/units";
+import { bytesInGB } from "utils/units";
interface Iprops {
plan: Plan;
@@ -63,7 +63,7 @@ export function PlanRow({
- {convertBytesToGBs(plan.storage)}
+ {bytesInGB(plan.storage)}
diff --git a/web/apps/photos/src/utils/file/index.ts b/web/apps/photos/src/utils/file/index.ts
index bb212ff21..98a8dd948 100644
--- a/web/apps/photos/src/utils/file/index.ts
+++ b/web/apps/photos/src/utils/file/index.ts
@@ -103,19 +103,6 @@ export async function getUpdatedEXIFFileForDownload(
}
}
-export function convertBytesToHumanReadable(
- bytes: number,
- precision = 2,
-): string {
- if (bytes === 0 || isNaN(bytes)) {
- return "0 MB";
- }
-
- const i = Math.floor(Math.log(bytes) / Math.log(1024));
- const sizes = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
- return (bytes / Math.pow(1024, i)).toFixed(precision) + " " + sizes[i];
-}
-
export async function downloadFile(file: EnteFile) {
try {
const fileReader = new FileReader();
diff --git a/web/apps/photos/src/utils/units.ts b/web/apps/photos/src/utils/units.ts
index 44ef4e023..20a90e4c2 100644
--- a/web/apps/photos/src/utils/units.ts
+++ b/web/apps/photos/src/utils/units.ts
@@ -4,8 +4,26 @@ const StorageUnits = ["B", "KB", "MB", "GB", "TB"];
const ONE_GB = 1024 * 1024 * 1024;
-export function convertBytesToGBs(bytes: number, precision = 0): string {
- return (bytes / (1024 * 1024 * 1024)).toFixed(precision);
+/**
+ * Convert the given number of {@link bytes} to their equivalent GB string with
+ * {@link precision}.
+ *
+ * The returned string does not have the GB prefix.
+ */
+export const bytesInGB = (bytes: number, precision = 0): string =>
+ (bytes / (1024 * 1024 * 1024)).toFixed(precision);
+
+export function convertBytesToHumanReadable(
+ bytes: number,
+ precision = 2,
+): string {
+ if (bytes === 0 || isNaN(bytes)) {
+ return "0 MB";
+ }
+
+ const i = Math.floor(Math.log(bytes) / Math.log(1024));
+ const sizes = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
+ return (bytes / Math.pow(1024, i)).toFixed(precision) + " " + sizes[i];
}
export function makeHumanReadableStorage(