use convertBytesToHumanReadable for logging
This commit is contained in:
parent
490fad83a6
commit
62ba9de838
5 changed files with 13 additions and 25 deletions
|
@ -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
|
||||
),
|
||||
}
|
||||
);
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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
|
||||
)}`
|
||||
);
|
||||
|
|
|
@ -2,7 +2,7 @@ export function convertBytesToHumanReadable(
|
|||
bytes: number,
|
||||
precision = 2
|
||||
): string {
|
||||
if (bytes === 0) {
|
||||
if (bytes === 0 || isNaN(bytes)) {
|
||||
return '0 MB';
|
||||
}
|
||||
|
||||
|
|
|
@ -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(' '));
|
||||
|
|
Loading…
Add table
Reference in a new issue