Prune
This commit is contained in:
parent
243d019e8b
commit
a3d06c54af
5 changed files with 20 additions and 50 deletions
|
@ -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",
|
||||
|
|
|
@ -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";
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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];
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue