diff --git a/src/services/heicConverter/heicConverterService.ts b/src/services/heicConverter/heicConverterService.ts index bc478e0b8..45b4aae90 100644 --- a/src/services/heicConverter/heicConverterService.ts +++ b/src/services/heicConverter/heicConverterService.ts @@ -4,7 +4,7 @@ import { createNewConvertWorker } from 'utils/heicConverter'; import { retryAsyncFunction } from 'utils/network'; import { logError } from 'utils/sentry'; import { addLogLine } from 'utils/logging'; -import { makeHumanReadableStorage } from 'utils/billing'; +import { convertBytesToHumanReadable } from 'utils/file/size'; const WORKER_POOL_SIZE = 2; const MAX_CONVERSION_IN_PARALLEL = 1; @@ -48,9 +48,9 @@ class HEICConverter { format ); addLogLine( - `originalFileSize:${makeHumanReadableStorage( + `originalFileSize:${convertBytesToHumanReadable( fileBlob?.size - )},convertedFileSize:${makeHumanReadableStorage( + )},convertedFileSize:${convertBytesToHumanReadable( convertedHEIC?.size )}, heic conversion time: ${ Date.now() - startTime @@ -70,11 +70,11 @@ class HEICConverter { Error(`converted heic fileSize is Zero`), 'converted heic fileSize is Zero', { - originalFileSize: makeHumanReadableStorage( - fileBlob?.size ?? 0 + originalFileSize: convertBytesToHumanReadable( + fileBlob?.size ), - convertedFileSize: makeHumanReadableStorage( - convertedHEIC?.size ?? 0 + convertedFileSize: convertBytesToHumanReadable( + convertedHEIC?.size ), } ); diff --git a/src/services/readerService.ts b/src/services/readerService.ts index d4f42cf27..c35122597 100644 --- a/src/services/readerService.ts +++ b/src/services/readerService.ts @@ -1,4 +1,5 @@ import { ElectronFile } from 'types/upload'; +import { convertBytesToHumanReadable } from 'utils/file/size'; import { logError } from 'utils/sentry'; export async function getUint8ArrayView( @@ -56,21 +57,6 @@ async function* fileChunkReaderMaker(file: File, chunkSize: number) { return null; } -// Temporary fix for window not defined caused on importing from utils/billing -// because this file is accessed inside worker and util/billing imports constants -// which has reference to window object, which cause error inside worker -// TODO: update worker to not read file themselves but rather have filedata passed to them - -function convertBytesToHumanReadable(bytes: number, precision = 2): string { - if (bytes === 0) { - 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]; -} - // depreciated // eslint-disable-next-line @typescript-eslint/no-unused-vars async function getUint8ArrayViewOld( diff --git a/src/utils/file/index.ts b/src/utils/file/index.ts index 3d29c026f..ae4fed4ef 100644 --- a/src/utils/file/index.ts +++ b/src/utils/file/index.ts @@ -27,7 +27,7 @@ import { NEW_FILE_MAGIC_METADATA, VISIBILITY_STATE } from 'types/magicMetadata'; import { IsArchived, updateMagicMetadataProps } from 'utils/magicMetadata'; import { addLogLine } from 'utils/logging'; -import { makeHumanReadableStorage } from 'utils/billing'; +import { convertBytesToHumanReadable } from './size'; export function downloadAsFile(filename: string, content: string) { const file = new Blob([content], { type: 'text/plain', @@ -337,7 +337,7 @@ async function getPlayableVideo(videoNameTitle: string, video: Uint8Array) { export async function getRenderableImage(fileName: string, imageBlob: Blob) { if (await isFileHEIC(imageBlob, fileName)) { addLogLine( - `HEICConverter called for ${fileName}-${makeHumanReadableStorage( + `HEICConverter called for ${fileName}-${convertBytesToHumanReadable( imageBlob.size )}` ); diff --git a/src/utils/file/size.ts b/src/utils/file/size.ts index a8480639a..e1b6b33e4 100644 --- a/src/utils/file/size.ts +++ b/src/utils/file/size.ts @@ -2,7 +2,7 @@ export function convertBytesToHumanReadable( bytes: number, precision = 2 ): string { - if (bytes === 0) { + if (bytes === 0 || isNaN(bytes)) { return '0 MB'; } diff --git a/src/utils/logging/index.ts b/src/utils/logging/index.ts index 0630080de..9a88b7676 100644 --- a/src/utils/logging/index.ts +++ b/src/utils/logging/index.ts @@ -3,7 +3,9 @@ import { convertBytesToHumanReadable } from 'utils/file/size'; import { formatDateTime } from 'utils/time'; import { saveLogLine, getLogs } from 'utils/storage'; +// commented out need fixing export function pipeConsoleLogsToDebugLogs() { + return; const oldLog = console.log; console.log = function (...args) { addLogLine(args.map((x) => JSON.stringify(x)).join(' '));