Manav Rathi 1 سال پیش
والد
کامیت
daeccdab32

+ 1 - 1
web/apps/photos/src/components/PhotoViewer/FileInfo/RenderFileName.tsx

@@ -7,7 +7,7 @@ import VideocamOutlined from "@mui/icons-material/VideocamOutlined";
 import Box from "@mui/material/Box";
 import { useEffect, useState } from "react";
 import { EnteFile } from "types/file";
-import { makeHumanReadableStorage } from "utils/billing";
+import { makeHumanReadableStorage } from "utils/units";
 import { changeFileName, updateExistingFilePubMetadata } from "utils/file";
 import { FileNameEditDialog } from "./FileNameEditDialog";
 import InfoItem from "./InfoItem";

+ 1 - 1
web/apps/photos/src/components/Sidebar/SubscriptionCard/contentOverlay/individual/usageSection.tsx

@@ -1,7 +1,7 @@
 import { SpaceBetweenFlex } from "@ente/shared/components/Container";
 import { Box, Typography } from "@mui/material";
 import { t } from "i18next";
-import { makeHumanReadableStorage } from "utils/billing";
+import { makeHumanReadableStorage } from "utils/units";
 
 import { Progressbar } from "../../styledComponents";
 

+ 1 - 1
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/billing";
+import { convertBytesToGBs, makeHumanReadableStorage } from "utils/units";
 
 const MobileSmallBox = styled(Box)`
     display: none;

+ 1 - 1
web/apps/photos/src/components/pages/gallery/PlanSelector/plans/BfAddOnRow.tsx

@@ -2,7 +2,7 @@ import { SpaceBetweenFlex } from "@ente/shared/components/Container";
 import { Box, styled, Typography } from "@mui/material";
 
 import { Trans } from "react-i18next";
-import { makeHumanReadableStorage } from "utils/billing";
+import { makeHumanReadableStorage } from "utils/units";
 
 const RowContainer = styled(SpaceBetweenFlex)(({ theme }) => ({
     // gap: theme.spacing(1.5),

+ 2 - 5
web/apps/photos/src/components/pages/gallery/PlanSelector/plans/planRow.tsx

@@ -6,11 +6,8 @@ import { Badge } from "components/Badge";
 import { PLAN_PERIOD } from "constants/gallery";
 import { t } from "i18next";
 import { Plan, Subscription } from "types/billing";
-import {
-    convertBytesToGBs,
-    hasPaidSubscription,
-    isUserSubscribedPlan,
-} from "utils/billing";
+import { hasPaidSubscription, isUserSubscribedPlan } from "utils/billing";
+import { convertBytesToGBs } from "utils/units";
 
 interface Iprops {
     plan: Plan;

+ 2 - 41
web/apps/photos/src/utils/billing/index.ts

@@ -31,44 +31,6 @@ enum RESPONSE_STATUS {
     fail = "fail",
 }
 
-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);
-}
-
-export function makeHumanReadableStorage(
-    bytes: number,
-    { roundUp } = { roundUp: false },
-): string {
-    if (bytes <= 0) {
-        return `0 ${t("STORAGE_UNITS.MB")}`;
-    }
-    const i = Math.floor(Math.log(bytes) / Math.log(1024));
-
-    let quantity = bytes / Math.pow(1024, i);
-    let unit = StorageUnits[i];
-
-    if (quantity > 100 && unit !== "GB") {
-        quantity /= 1024;
-        unit = StorageUnits[i + 1];
-    }
-
-    quantity = Number(quantity.toFixed(1));
-
-    if (bytes >= 10 * ONE_GB) {
-        if (roundUp) {
-            quantity = Math.ceil(quantity);
-        } else {
-            quantity = Math.round(quantity);
-        }
-    }
-
-    return `${quantity} ${t(`STORAGE_UNITS.${unit}`)}`;
-}
-
 export function hasPaidSubscription(subscription: Subscription) {
     return (
         subscription &&
@@ -160,9 +122,8 @@ export function isSubscriptionPastDue(subscription: Subscription) {
     );
 }
 
-export function isPopularPlan(plan: Plan) {
-    return plan.storage === 100 * ONE_GB;
-}
+export const isPopularPlan = (plan: Plan) =>
+    plan.storage === 100 * 1024 * 1024 * 1024; /* 100 GB */
 
 export async function updateSubscription(
     plan: Plan,

+ 39 - 0
web/apps/photos/src/utils/units.ts

@@ -0,0 +1,39 @@
+import { t } from "i18next";
+
+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);
+}
+
+export function makeHumanReadableStorage(
+    bytes: number,
+    { roundUp } = { roundUp: false },
+): string {
+    if (bytes <= 0) {
+        return `0 ${t("STORAGE_UNITS.MB")}`;
+    }
+    const i = Math.floor(Math.log(bytes) / Math.log(1024));
+
+    let quantity = bytes / Math.pow(1024, i);
+    let unit = StorageUnits[i];
+
+    if (quantity > 100 && unit !== "GB") {
+        quantity /= 1024;
+        unit = StorageUnits[i + 1];
+    }
+
+    quantity = Number(quantity.toFixed(1));
+
+    if (bytes >= 10 * ONE_GB) {
+        if (roundUp) {
+            quantity = Math.ceil(quantity);
+        } else {
+            quantity = Math.round(quantity);
+        }
+    }
+
+    return `${quantity} ${t(`STORAGE_UNITS.${unit}`)}`;
+}