move getFileHash to crypto

This commit is contained in:
Rushikesh Tote 2022-05-18 12:41:39 +05:30
parent b0616a2142
commit f49b53db0f
3 changed files with 11 additions and 9 deletions

View file

@ -12,13 +12,14 @@ import {
import { NULL_EXTRACTED_METADATA, NULL_LOCATION } from 'constants/upload';
import { splitFilenameAndExtension } from 'utils/file';
import { getVideoMetadata } from './videoMetadataService';
import { getFileHash, getFileNameSize } from 'utils/upload';
import { getFileNameSize } from 'utils/upload';
import { logUploadInfo } from 'utils/upload';
import {
parseDateFromFusedDateString,
getUnixTimeInMicroSeconds,
tryToParseDateTime,
} from 'utils/time';
import { getFileHash } from 'utils/crypto';
interface ParsedMetadataJSONWithTitle {
title: string;

View file

@ -7,6 +7,8 @@ import { getActualKey, getToken } from 'utils/common/key';
import { setRecoveryKey } from 'services/userService';
import { logError } from 'utils/sentry';
import { ComlinkWorker } from 'utils/comlink';
import { ElectronFile } from 'types/upload';
import { cryptoGenericHash } from './libsodium';
export interface B64EncryptionResult {
encryptedData: string;
@ -196,3 +198,10 @@ export async function encryptWithRecoveryKey(key: string) {
return encryptedKey;
}
export default CryptoWorker;
export async function getFileHash(file: File | ElectronFile) {
const hash = await cryptoGenericHash(
new Uint8Array(await file.arrayBuffer())
);
return hash;
}

View file

@ -4,7 +4,6 @@ import { convertBytesToHumanReadable } from 'utils/billing';
import { formatDateTime } from 'utils/file';
import { getLogs, saveLogLine } from 'utils/storage';
import { A_SEC_IN_MICROSECONDS } from 'constants/upload';
import { cryptoGenericHash } from 'utils/crypto/libsodium';
const TYPE_JSON = 'json';
const DEDUPE_COLLECTION = new Set(['icloud library', 'icloudlibrary']);
@ -94,10 +93,3 @@ export function areFileWithCollectionsSame(
): boolean {
return firstFile.localID === secondFile.localID;
}
export async function getFileHash(file: File | ElectronFile) {
const hash = await cryptoGenericHash(
new Uint8Array(await file.arrayBuffer())
);
return hash;
}