Skip to content

armgit / ente

Public Imported from GitHub
0

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

Prune

Manav Rathia3d06c54afc0
diff --git a/web/apps/photos/src/components/PhotoList/dedupe.tsx b/web/apps/photos/src/components/PhotoList/dedupe.tsx
index 9c86ba24f1..7181f62675 100644
--- a/web/apps/photos/src/components/PhotoList/dedupe.tsx
+++ b/web/apps/photos/src/components/PhotoList/dedupe.tsx
@@ -1,4 +1,3 @@
-import { convertBytesToHumanReadable } from "@/next/file";
import { FlexWrapper } from "@ente/shared/components/Container";
import { Box, styled } from "@mui/material";
import {
@@ -20,6 +19,7 @@ import {
} from "react-window";
import { Duplicate } from "services/deduplicationService";
import { EnteFile } from "types/file";
+import { convertBytesToHumanReadable } from "utils/file";
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 48454fa691..91f712df1b 100644
--- a/web/apps/photos/src/components/PhotoList/index.tsx
+++ b/web/apps/photos/src/components/PhotoList/index.tsx
@@ -1,4 +1,3 @@
-import { convertBytesToHumanReadable } from "@/next/file";
import { FlexWrapper } from "@ente/shared/components/Container";
import { formatDate, getDate, isSameDay } from "@ente/shared/time/format";
import { Box, Checkbox, Link, Typography, styled } from "@mui/material";
@@ -23,6 +22,7 @@ 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";
diff --git a/web/apps/photos/src/services/heic-convert.ts b/web/apps/photos/src/services/heic-convert.ts
index 478cce2185..c2ea198391 100644
--- a/web/apps/photos/src/services/heic-convert.ts
+++ b/web/apps/photos/src/services/heic-convert.ts
@@ -1,4 +1,3 @@
-import { convertBytesToHumanReadable } from "@/next/file";
import log from "@/next/log";
import { ComlinkWorker } from "@/next/worker/comlink-worker";
import { CustomError } from "@ente/shared/error";
@@ -51,15 +50,10 @@ class HEICConverter {
const startTime = Date.now();
const convertedHEIC =
await worker.heicToJPEG(fileBlob);
- log.info(
- `originalFileSize:${convertBytesToHumanReadable(
- fileBlob?.size,
- )},convertedFileSize:${convertBytesToHumanReadable(
- convertedHEIC?.size,
- )}, heic conversion time: ${
- Date.now() - startTime
- }ms `,
+ const ms = Math.round(
+ Date.now() - startTime,
);
+ log.debug(() => `heic => jpeg (${ms} ms)`);
clearTimeout(timeout);
resolve(convertedHEIC);
} catch (e) {
@@ -71,18 +65,7 @@ class HEICConverter {
);
if (!convertedHEIC || convertedHEIC?.size === 0) {
log.error(
- `converted heic fileSize is Zero - ${JSON.stringify(
- {
- originalFileSize:
- convertBytesToHumanReadable(
- fileBlob?.size ?? 0,
- ),
- convertedFileSize:
- convertBytesToHumanReadable(
- convertedHEIC?.size ?? 0,
- ),
- },
- )}`,
+ `Converted HEIC file is empty (original was ${fileBlob?.size} bytes)`,
);
}
await new Promise((resolve) => {
@@ -94,7 +77,7 @@ class HEICConverter {
this.workerPool.push(convertWorker);
return convertedHEIC;
} catch (e) {
- log.error("heic conversion failed", e);
+ log.error("HEIC conversion failed", e);
convertWorker.terminate();
this.workerPool.push(createComlinkWorker());
throw e;
diff --git a/web/apps/photos/src/utils/file/index.ts b/web/apps/photos/src/utils/file/index.ts
index 5d7762abfc..abbc8b0fa3 100644
--- a/web/apps/photos/src/utils/file/index.ts
+++ b/web/apps/photos/src/utils/file/index.ts
@@ -116,6 +116,19 @@ 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/packages/next/file.ts b/web/packages/next/file.ts
index 56d27b79b5..bd2c043930 100644
--- a/web/packages/next/file.ts
+++ b/web/packages/next/file.ts
@@ -1,5 +1,3 @@
-import type { ElectronFile } from "./types/file";
-
/**
* The two parts of a file name - the name itself, and an (optional) extension.
*
@@ -82,27 +80,3 @@ export const dirname = (path: string) => {
}
return pathComponents.join("/");
};
-
-/**
- * Return a short description of the given {@link fileOrPath} suitable for
- * helping identify it in log messages.
- */
-export const fopLabel = (fileOrPath: File | string) =>
- fileOrPath instanceof File ? `File(${fileOrPath.name})` : fileOrPath;
-
-export function getFileNameSize(file: File | ElectronFile) {
- return `${file.name}_${convertBytesToHumanReadable(file.size)}`;
-}
-
-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];
-}