Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Move more

Manav Rathia282c6cb40ba
diff --git a/web/apps/photos/src/components/PhotoList/dedupe.tsx b/web/apps/photos/src/components/PhotoList/dedupe.tsx
index 56a9638e3f..1652ff176f 100644
--- a/web/apps/photos/src/components/PhotoList/dedupe.tsx
+++ b/web/apps/photos/src/components/PhotoList/dedupe.tsx
@@ -1,4 +1,5 @@
import { EnteFile } from "@/new/photos/types/file";
+import { formattedByteSize } from "@/new/photos/utils/units";
import { FlexWrapper } from "@ente/shared/components/Container";
import { Box, styled } from "@mui/material";
import {
@@ -19,7 +20,6 @@ import {
areEqual,
} from "react-window";
import { Duplicate } from "services/deduplicationService";
-import { formattedByteSize } 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 85c6db57cb..1f4b0bfb06 100644
--- a/web/apps/photos/src/components/PhotoList/index.tsx
+++ b/web/apps/photos/src/components/PhotoList/index.tsx
@@ -1,4 +1,5 @@
import { EnteFile } from "@/new/photos/types/file";
+import { formattedByteSize } from "@/new/photos/utils/units";
import { FlexWrapper } from "@ente/shared/components/Container";
import { formatDate } from "@ente/shared/time/format";
import { Box, Checkbox, Link, Typography, styled } from "@mui/material";
@@ -24,7 +25,6 @@ import {
} from "react-window";
import { handleSelectCreator } from "utils/photoFrame";
import { PublicCollectionGalleryContext } from "utils/publicCollectionGallery";
-import { formattedByteSize } from "utils/units";
const FOOTER_HEIGHT = 90;
const ALBUM_FOOTER_HEIGHT = 75;
diff --git a/web/apps/photos/src/components/PhotoViewer/FileInfo/RenderFileName.tsx b/web/apps/photos/src/components/PhotoViewer/FileInfo/RenderFileName.tsx
index caa9be2de4..b4a932b9aa 100644
--- a/web/apps/photos/src/components/PhotoViewer/FileInfo/RenderFileName.tsx
+++ b/web/apps/photos/src/components/PhotoViewer/FileInfo/RenderFileName.tsx
@@ -1,5 +1,6 @@
import { FILE_TYPE } from "@/media/file-type";
import { EnteFile } from "@/new/photos/types/file";
+import { formattedByteSize } from "@/new/photos/utils/units";
import { nameAndExtension } from "@/next/file";
import log from "@/next/log";
import { FlexWrapper } from "@ente/shared/components/Container";
@@ -8,7 +9,6 @@ import VideocamOutlined from "@mui/icons-material/VideocamOutlined";
import Box from "@mui/material/Box";
import { useEffect, useState } from "react";
import { changeFileName, updateExistingFilePubMetadata } from "utils/file";
-import { formattedByteSize } from "utils/units";
import { FileNameEditDialog } from "./FileNameEditDialog";
import InfoItem from "./InfoItem";
diff --git a/web/apps/photos/src/components/Sidebar/SubscriptionCard/contentOverlay/individual/usageSection.tsx b/web/apps/photos/src/components/Sidebar/SubscriptionCard/contentOverlay/individual/usageSection.tsx
index 8975941ad5..251a58d823 100644
--- a/web/apps/photos/src/components/Sidebar/SubscriptionCard/contentOverlay/individual/usageSection.tsx
+++ b/web/apps/photos/src/components/Sidebar/SubscriptionCard/contentOverlay/individual/usageSection.tsx
@@ -1,7 +1,7 @@
+import { formattedStorageByteSize } from "@/new/photos/utils/units";
import { SpaceBetweenFlex } from "@ente/shared/components/Container";
import { Box, Typography } from "@mui/material";
import { t } from "i18next";
-import { formattedStorageByteSize } from "utils/units";
import { Progressbar } from "../../styledComponents";
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 7f2712f738..4ad0ed2149 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 { bytesInGB, formattedStorageByteSize } from "@/new/photos/utils/units";
+import { Box, Typography, styled } from "@mui/material";
import { t } from "i18next";
-import { bytesInGB, formattedStorageByteSize } from "utils/units";
const MobileSmallBox = styled(Box)`
display: none;
diff --git a/web/apps/photos/src/components/Upload/Uploader.tsx b/web/apps/photos/src/components/Upload/Uploader.tsx
index 85e660672e..170d2fcdc8 100644
--- a/web/apps/photos/src/components/Upload/Uploader.tsx
+++ b/web/apps/photos/src/components/Upload/Uploader.tsx
@@ -1,3 +1,4 @@
+import { exportMetadataDirectoryName } from "@/new/photos/services/export";
import { basename } from "@/next/file";
import log from "@/next/log";
import type { CollectionMapping, Electron, ZipItem } from "@/next/types/ipc";
@@ -15,7 +16,6 @@ import { GalleryContext } from "pages/gallery";
import { useContext, useEffect, useRef, useState } from "react";
import billingService from "services/billingService";
import { getLatestCollections } from "services/collectionService";
-import { exportMetadataDirectoryName } from "services/export";
import {
getPublicCollectionUID,
getPublicCollectionUploaderName,
diff --git a/web/apps/photos/src/components/pages/gallery/PlanSelector/card.tsx b/web/apps/photos/src/components/pages/gallery/PlanSelector/card.tsx
index 55e93979de..17f0b6e6e7 100644
--- a/web/apps/photos/src/components/pages/gallery/PlanSelector/card.tsx
+++ b/web/apps/photos/src/components/pages/gallery/PlanSelector/card.tsx
@@ -1,3 +1,4 @@
+import { bytesInGB } from "@/new/photos/utils/units";
import log from "@/next/log";
import { SpaceBetweenFlex } from "@ente/shared/components/Container";
import { SUPPORT_EMAIL } from "@ente/shared/constants/urls";
@@ -27,7 +28,6 @@ import {
planForSubscription,
updateSubscription,
} from "utils/billing";
-import { bytesInGB } from "utils/units";
import { getLocalUserDetails } from "utils/user";
import { getTotalFamilyUsage, isPartOfFamily } from "utils/user/family";
import { ManageSubscription } from "./manageSubscription";
diff --git a/web/apps/photos/src/components/pages/gallery/PlanSelector/plans/BfAddOnRow.tsx b/web/apps/photos/src/components/pages/gallery/PlanSelector/plans/BfAddOnRow.tsx
index 5f7e13deb8..7b375f5d73 100644
--- a/web/apps/photos/src/components/pages/gallery/PlanSelector/plans/BfAddOnRow.tsx
+++ b/web/apps/photos/src/components/pages/gallery/PlanSelector/plans/BfAddOnRow.tsx
@@ -1,8 +1,8 @@
import { SpaceBetweenFlex } from "@ente/shared/components/Container";
import { Box, styled, Typography } from "@mui/material";
+import { formattedStorageByteSize } from "@/new/photos/utils/units";
import { Trans } from "react-i18next";
-import { formattedStorageByteSize } from "utils/units";
const RowContainer = styled(SpaceBetweenFlex)(({ theme }) => ({
// gap: theme.spacing(1.5),
diff --git a/web/apps/photos/src/components/pages/gallery/PlanSelector/plans/index.tsx b/web/apps/photos/src/components/pages/gallery/PlanSelector/plans/index.tsx
index 31e97c68e6..e83ca781ee 100644
--- a/web/apps/photos/src/components/pages/gallery/PlanSelector/plans/index.tsx
+++ b/web/apps/photos/src/components/pages/gallery/PlanSelector/plans/index.tsx
@@ -1,3 +1,4 @@
+import { formattedStorageByteSize } from "@/new/photos/utils/units";
import { SpaceBetweenFlex } from "@ente/shared/components/Container";
import ArrowForward from "@mui/icons-material/ArrowForward";
import { Box, IconButton, Stack, Typography, styled } from "@mui/material";
@@ -12,7 +13,6 @@ import {
isPopularPlan,
isUserSubscribedPlan,
} from "utils/billing";
-import { formattedStorageByteSize } from "utils/units";
import { PlanRow } from "./planRow";
interface Iprops {
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 9f1351b120..9701baf01a 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
@@ -1,3 +1,4 @@
+import { bytesInGB } from "@/new/photos/utils/units";
import { FlexWrapper, FluidContainer } from "@ente/shared/components/Container";
import ArrowForward from "@mui/icons-material/ArrowForward";
import Done from "@mui/icons-material/Done";
@@ -7,7 +8,6 @@ import { PLAN_PERIOD } from "constants/gallery";
import { t } from "i18next";
import { Plan, Subscription } from "types/billing";
import { hasPaidSubscription, isUserSubscribedPlan } from "utils/billing";
-import { bytesInGB } from "utils/units";
interface Iprops {
plan: Plan;
diff --git a/web/apps/photos/src/services/export/index.ts b/web/apps/photos/src/services/export/index.ts
index df7d23eddf..fcf387fef3 100644
--- a/web/apps/photos/src/services/export/index.ts
+++ b/web/apps/photos/src/services/export/index.ts
@@ -1,9 +1,15 @@
import { FILE_TYPE } from "@/media/file-type";
import { decodeLivePhoto } from "@/media/live-photo";
import type { Metadata } from "@/media/types/file";
+import {
+ exportMetadataDirectoryName,
+ exportTrashDirectoryName,
+} from "@/new/photos/services/export";
import { getAllLocalFiles } from "@/new/photos/services/files";
import { EnteFile } from "@/new/photos/types/file";
import { mergeMetadata } from "@/new/photos/utils/file";
+import { safeDirectoryName, safeFileName } from "@/new/photos/utils/native-fs";
+import { writeStream } from "@/new/photos/utils/native-stream";
import { ensureElectron } from "@/next/electron";
import log from "@/next/log";
import { wait } from "@/utils/promise";
@@ -31,8 +37,6 @@ import {
getNonEmptyPersonalCollections,
} from "utils/collection";
import { getPersonalFiles, getUpdatedEXIFFileForDownload } from "utils/file";
-import { safeDirectoryName, safeFileName } from "utils/native-fs";
-import { writeStream } from "utils/native-stream";
import { getAllLocalCollections } from "../collectionService";
import downloadManager from "../download";
import { migrateExport } from "./migration";
@@ -46,18 +50,6 @@ const exportRecordFileName = "export_status.json";
*/
const exportDirectoryName = "Ente Photos";
-/**
- * Name of the directory in which we put our metadata when exporting to the file
- * system.
- */
-export const exportMetadataDirectoryName = "metadata";
-
-/**
- * Name of the directory in which we keep trash items when deleting files that
- * have been exported to the local disk previously.
- */
-export const exportTrashDirectoryName = "Trash";
-
export enum ExportStage {
INIT = 0,
MIGRATION = 1,
diff --git a/web/apps/photos/src/services/export/migration.ts b/web/apps/photos/src/services/export/migration.ts
index 75ab0e2f11..f46fc0a48e 100644
--- a/web/apps/photos/src/services/export/migration.ts
+++ b/web/apps/photos/src/services/export/migration.ts
@@ -3,6 +3,11 @@ import { decodeLivePhoto } from "@/media/live-photo";
import { getAllLocalFiles } from "@/new/photos/services/files";
import { EnteFile } from "@/new/photos/types/file";
import { mergeMetadata } from "@/new/photos/utils/file";
+import {
+ safeDirectoryName,
+ safeFileName,
+ sanitizeFilename,
+} from "@/new/photos/utils/native-fs";
import { ensureElectron } from "@/next/electron";
import { nameAndExtension } from "@/next/file";
import log from "@/next/log";
@@ -24,11 +29,6 @@ import {
} from "types/export";
import { getNonEmptyPersonalCollections } from "utils/collection";
import { getIDBasedSortedFiles, getPersonalFiles } from "utils/file";
-import {
- safeDirectoryName,
- safeFileName,
- sanitizeFilename,
-} from "utils/native-fs";
import {
exportMetadataDirectoryName,
getCollectionIDFromFileUID,
diff --git a/web/apps/photos/src/services/ffmpeg.ts b/web/apps/photos/src/services/ffmpeg.ts
index 800df1e953..342a6fca57 100644
--- a/web/apps/photos/src/services/ffmpeg.ts
+++ b/web/apps/photos/src/services/ffmpeg.ts
@@ -1,3 +1,8 @@
+import {
+ readConvertToMP4Done,
+ readConvertToMP4Stream,
+ writeConvertToMP4Stream,
+} from "@/new/photos/utils/native-stream";
import type { Electron } from "@/next/types/ipc";
import { ComlinkWorker } from "@/next/worker/comlink-worker";
import { validateAndGetCreationUnixTimeInMicroSeconds } from "@ente/shared/time";
@@ -9,11 +14,6 @@ import {
} from "constants/ffmpeg";
import { NULL_LOCATION } from "constants/upload";
import type { ParsedExtractedMetadata } from "types/metadata";
-import {
- readConvertToMP4Done,
- readConvertToMP4Stream,
- writeConvertToMP4Stream,
-} from "utils/native-stream";
import type { DedicatedFFmpegWorker } from "worker/ffmpeg.worker";
import {
toDataOrPathOrZipEntry,
diff --git a/web/apps/photos/src/services/upload/takeout.ts b/web/apps/photos/src/services/upload/takeout.ts
index 24c0a9d267..2cd0f342d6 100644
--- a/web/apps/photos/src/services/upload/takeout.ts
+++ b/web/apps/photos/src/services/upload/takeout.ts
@@ -1,11 +1,11 @@
/** @file Dealing with the JSON metadata in Google Takeouts */
+import { readStream } from "@/new/photos/utils/native-stream";
import { ensureElectron } from "@/next/electron";
import { nameAndExtension } from "@/next/file";
import log from "@/next/log";
import { NULL_LOCATION } from "constants/upload";
import type { Location } from "types/metadata";
-import { readStream } from "utils/native-stream";
import type { UploadItem } from "./types";
export interface ParsedMetadataJSON {
diff --git a/web/apps/photos/src/services/upload/uploadService.ts b/web/apps/photos/src/services/upload/uploadService.ts
index 9a5885f624..bfe682cb1b 100644
--- a/web/apps/photos/src/services/upload/uploadService.ts
+++ b/web/apps/photos/src/services/upload/uploadService.ts
@@ -12,6 +12,7 @@ import {
} from "@/new/photos/types/file";
import { EncryptedMagicMetadata } from "@/new/photos/types/magicMetadata";
import { detectFileTypeInfoFromChunk } from "@/new/photos/utils/detect-type";
+import { readStream } from "@/new/photos/utils/native-stream";
import { ensureElectron } from "@/next/electron";
import { basename } from "@/next/file";
import log from "@/next/log";
@@ -39,7 +40,6 @@ import {
getNonEmptyMagicMetadataProps,
updateMagicMetadata,
} from "utils/magicMetadata";
-import { readStream } from "utils/native-stream";
import * as convert from "xml-js";
import { tryParseEpochMicrosecondsFromFileName } from "./date";
import publicUploadHttpClient from "./publicUploadHttpClient";
diff --git a/web/apps/photos/src/utils/collection/index.ts b/web/apps/photos/src/utils/collection/index.ts
index 12fffe6bfa..d6081567f3 100644
--- a/web/apps/photos/src/utils/collection/index.ts
+++ b/web/apps/photos/src/utils/collection/index.ts
@@ -1,6 +1,7 @@
import { getAllLocalFiles, getLocalFiles } from "@/new/photos/services/files";
import { EnteFile } from "@/new/photos/types/file";
import { SUB_TYPE, VISIBILITY_STATE } from "@/new/photos/types/magicMetadata";
+import { safeDirectoryName } from "@/new/photos/utils/native-fs";
import { ensureElectron } from "@/next/electron";
import log from "@/next/log";
import { CustomError } from "@ente/shared/error";
@@ -43,7 +44,6 @@ import {
import { SetFilesDownloadProgressAttributes } from "types/gallery";
import { downloadFilesWithProgress } from "utils/file";
import { isArchivedCollection, updateMagicMetadata } from "utils/magicMetadata";
-import { safeDirectoryName } from "utils/native-fs";
export enum COLLECTION_OPS_TYPE {
ADD,
diff --git a/web/apps/photos/src/utils/file/index.ts b/web/apps/photos/src/utils/file/index.ts
index 759117390c..13b3c2fe61 100644
--- a/web/apps/photos/src/utils/file/index.ts
+++ b/web/apps/photos/src/utils/file/index.ts
@@ -12,6 +12,8 @@ import {
import { VISIBILITY_STATE } from "@/new/photos/types/magicMetadata";
import { detectFileTypeInfo } from "@/new/photos/utils/detect-type";
import { mergeMetadata } from "@/new/photos/utils/file";
+import { safeFileName } from "@/new/photos/utils/native-fs";
+import { writeStream } from "@/new/photos/utils/native-stream";
import { lowercaseExtension } from "@/next/file";
import log from "@/next/log";
import { type Electron } from "@/next/types/ipc";
@@ -36,8 +38,6 @@ import {
SetFilesDownloadProgressAttributesCreator,
} from "types/gallery";
import { isArchivedFile, updateMagicMetadata } from "utils/magicMetadata";
-import { safeFileName } from "utils/native-fs";
-import { writeStream } from "utils/native-stream";
export enum FILE_OPS_TYPE {
DOWNLOAD,
diff --git a/web/packages/new/photos/services/export.ts b/web/packages/new/photos/services/export.ts
new file mode 100644
index 0000000000..40229741ed
--- /dev/null
+++ b/web/packages/new/photos/services/export.ts
@@ -0,0 +1,11 @@
+/**
+ * Name of the directory in which we put our metadata when exporting to the file
+ * system.
+ */
+export const exportMetadataDirectoryName = "metadata";
+
+/**
+ * Name of the directory in which we keep trash items when deleting files that
+ * have been exported to the local disk previously.
+ */
+export const exportTrashDirectoryName = "Trash";
diff --git a/web/packages/new/photos/utils/native-fs.ts b/web/packages/new/photos/utils/native-fs.ts
index 27ebdd1c12..666efc4fca 100644
--- a/web/packages/new/photos/utils/native-fs.ts
+++ b/web/packages/new/photos/utils/native-fs.ts
@@ -5,12 +5,12 @@
* written for use by the code that runs in our desktop app.
*/
-import { nameAndExtension } from "@/next/file";
-import sanitize from "sanitize-filename";
import {
exportMetadataDirectoryName,
exportTrashDirectoryName,
-} from "services/export";
+} from "@/new/photos/services/export";
+import { nameAndExtension } from "@/next/file";
+import sanitize from "sanitize-filename";
/**
* Sanitize string for use as file or directory name.
diff --git a/web/packages/new/photos/utils/native-stream.ts b/web/packages/new/photos/utils/native-stream.ts
index e922c26219..9c38897367 100644
--- a/web/packages/new/photos/utils/native-stream.ts
+++ b/web/packages/new/photos/utils/native-stream.ts
@@ -52,7 +52,7 @@ export const readStream = async (
const res = await fetch(req);
if (!res.ok)
throw new Error(
- `Failed to read stream from ${url}: HTTP ${res.status}`,
+ `Failed to read stream from ${url.href}: HTTP ${res.status}`,
);
const size = readNumericHeader(res, "Content-Length");
@@ -63,7 +63,7 @@ export const readStream = async (
const readNumericHeader = (res: Response, key: string) => {
const valueText = res.headers.get(key);
- const value = +valueText;
+ const value = valueText === null ? NaN : +valueText;
if (isNaN(value))
throw new Error(
`Expected a numeric ${key} when reading a stream response, instead got ${valueText}`,
@@ -111,7 +111,9 @@ export const writeStream = async (
const res = await fetch(req);
if (!res.ok)
- throw new Error(`Failed to write stream to ${url}: HTTP ${res.status}`);
+ throw new Error(
+ `Failed to write stream to ${url.href}: HTTP ${res.status}`,
+ );
};
/**
@@ -161,7 +163,7 @@ export const readConvertToMP4Stream = async (
const res = await fetch(req);
if (!res.ok)
throw new Error(
- `Failed to read stream from ${url}: HTTP ${res.status}`,
+ `Failed to read stream from ${url.href}: HTTP ${res.status}`,
);
return res.blob();
@@ -185,5 +187,7 @@ export const readConvertToMP4Done = async (
const req = new Request(url, { method: "GET" });
const res = await fetch(req);
if (!res.ok)
- throw new Error(`Failed to close stream at ${url}: HTTP ${res.status}`);
+ throw new Error(
+ `Failed to close stream at ${url.href}: HTTP ${res.status}`,
+ );
};