π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
1
Manav Rathi7993a076077e
diff --git a/web/apps/photos/src/components/PhotoList/dedupe.tsx b/web/apps/photos/src/components/PhotoList/dedupe.tsxindex ab7badf1f6..be412ad782 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.tsxindex 4803995d4f..508e9eab5a 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.tsxindex 8ef5bea5ec..90705753b9 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")}`}</Typography></MobileSmallBox></Box>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.tsxindex 4ef76a491f..0ef4b15947 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")}</Typography><Typography variant="small" color={"text.muted"}>- {convertBytesToGBs(subscription.storage, 2)}{" "}- {t("GB")}+ {bytesInGB(subscription.storage, 2)} {t("GB")}</Typography></Box><IconButton onClick={closeModal} color="secondary">@@ -50,7 +46,7 @@ export default function PaidSubscriptionPlanSelectorCard({<Transi18nKey="CURRENT_USAGE"values={{- usage: `${convertBytesToGBs(usage, 2)} ${t("GB")}`,+ usage: `${bytesInGB(usage, 2)} ${t("GB")}`,}}/></Typography>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.tsxindex ca01b40b39..bb2347ddcc 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({<PlanRowContainer><TopAlignedFluidContainer><Typography variant="h1" fontWeight={"bold"}>- {convertBytesToGBs(plan.storage)}+ {bytesInGB(plan.storage)}</Typography><FlexWrapper flexWrap={"wrap"} gap={1}><Typography variant="h3" color="text.muted">diff --git a/web/apps/photos/src/utils/file/index.ts b/web/apps/photos/src/utils/file/index.tsindex bb212ff21e..98a8dd9481 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.tsindex 44ef4e023e..20a90e4c29 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(