Fix build + switch to common pkg

This commit is contained in:
Neeraj Gupta 2024-01-20 10:03:26 +05:30
parent 1e583414d3
commit dff2a38de9
22 changed files with 35 additions and 553 deletions

View file

@ -1,3 +1,4 @@
import { logError } from '@ente/shared/sentry';
import PairedSuccessfullyOverlay from 'components/PairedSuccessfullyOverlay';
import Theatre from 'components/Theatre';
import { FILE_TYPE } from 'constants/file';
@ -7,7 +8,6 @@ import { getCollectionWithKey } from 'services/collectionService';
import { syncFiles } from 'services/fileService';
import { EnteFile } from 'types/file';
import { downloadFileAsBlob, isRawFileFromFileName } from 'utils/file';
import { logError } from 'utils/sentry';
export const SlideshowContext = createContext<{
showNextSlide: () => void;
@ -31,13 +31,11 @@ export default function Slideshow() {
try {
// get requested collection id from localStorage
const requestedCollectionID =
window.localStorage.getItem('targetCollectionId');
window.localStorage.getItem('collectionID');
const requestedCollectionKey = window.localStorage.getItem(
'targetCollectionKey'
);
const castToken = window.localStorage.getItem('token');
const requestedCollectionKey =
window.localStorage.getItem('collectionKey');
const castToken = window.localStorage.getItem('castToken');
const collection = await getCollectionWithKey(
Number(requestedCollectionID),

View file

@ -1,4 +1,4 @@
import { logError } from 'utils/sentry';
import { logError } from '@ente/shared/sentry';
import { CacheStorageFactory } from './cacheStorageFactory';
const SecurityError = 'SecurityError';

View file

@ -5,8 +5,8 @@ import {
} from 'constants/ffmpeg';
import { ElectronFile } from 'types/upload';
import { parseFFmpegExtractedMetadata } from 'utils/ffmpeg';
import { logError } from 'utils/sentry';
import ffmpegFactory from './ffmpegFactory';
import { logError } from '@ente/shared/sentry';
export async function generateVideoThumbnail(
file: File | ElectronFile

View file

@ -1,10 +1,8 @@
import { getEndpoint } from '@ente/shared/network/api';
import localForage from 'utils/storage/localForage';
import { getToken } from '@ente/shared/storage/localStorage/helpers';
import { Collection } from 'types/collection';
import { logError } from 'utils/sentry';
import {
decryptFile,
getLatestVersionFiles,
@ -21,7 +19,6 @@ import {
} from 'types/file';
import { SetFiles } from 'types/gallery';
import { BulkUpdateMagicMetadataRequest } from 'types/magicMetadata';
import { addLogLine } from 'utils/logging';
import ComlinkCryptoWorker from 'utils/comlink/ComlinkCryptoWorker';
import {
getCollectionLastSyncTime,
@ -30,6 +27,9 @@ import {
import { REQUEST_BATCH_SIZE } from 'constants/api';
import { batch } from '@ente/shared/batch';
import HTTPService from '@ente/shared/network/HTTPService';
import localForage from '@ente/shared/storage/localForage';
import { logError } from '@ente/shared/sentry';
import { addLogLine } from '@ente/shared/logging';
const ENDPOINT = getEndpoint();
const FILES_TABLE = 'files';

View file

@ -1,4 +1,4 @@
import { logError } from 'utils/sentry';
import { logError } from '@ente/shared/sentry';
import WasmHEICConverterService from './wasmHeicConverter/wasmHEICConverterService';
class HeicConversionService {

View file

@ -6,7 +6,7 @@ import {
} from 'constants/upload';
import { CustomError } from 'utils/error';
import { getFileExtension } from 'utils/file';
import { logError } from 'utils/sentry';
import { logError } from '@ente/shared/sentry';
import { getUint8ArrayView } from './readerService';
import FileType, { FileTypeResult } from 'file-type';
import { convertBytesToHumanReadable } from 'utils/file/size';

View file

@ -3,7 +3,7 @@ import { Location } from 'types/upload';
import exifr from 'exifr';
import piexif from 'piexifjs';
import { FileTypeInfo } from 'types/upload';
import { logError } from 'utils/sentry';
import { logError } from '@ente/shared/sentry';
import { validateAndGetCreationUnixTimeInMicroSeconds } from 'utils/time';
import { CustomError } from 'utils/error';

View file

@ -2,9 +2,9 @@ import { promiseWithTimeout } from '@ente/shared/promise';
import { createFFmpeg, FFmpeg } from 'ffmpeg-wasm';
import QueueProcessor from 'services/queueProcessor';
import { getUint8ArrayView } from 'services/readerService';
import { addLogLine } from 'utils/logging';
import { logError } from 'utils/sentry';
import { logError } from '@ente/shared/sentry';
import { generateTempName } from 'utils/temp';
import { addLogLine } from '@ente/shared/logging';
const INPUT_PATH_PLACEHOLDER = 'INPUT';
const FFMPEG_PLACEHOLDER = 'FFMPEG';

View file

@ -1,12 +1,12 @@
import QueueProcessor from 'services/queueProcessor';
import { CustomError } from 'utils/error';
import { retryAsyncFunction } from 'utils/network';
import { addLogLine } from 'utils/logging';
import { DedicatedConvertWorker } from 'worker/convert.worker';
import { ComlinkWorker } from 'utils/comlink/comlinkWorker';
import { convertBytesToHumanReadable } from 'utils/file/size';
import { getDedicatedConvertWorker } from 'utils/comlink/ComlinkConvertWorker';
import { logError } from '@ente/shared/sentry';
import { addLogLine } from '@ente/shared/logging';
const WORKER_POOL_SIZE = 2;
const MAX_CONVERSION_IN_PARALLEL = 1;

View file

@ -1,25 +0,0 @@
import { PLAN_PERIOD } from 'constants/gallery';
export interface Subscription {
id: number;
userID: number;
productID: string;
storage: number;
originalTransactionID: string;
expiryTime: number;
paymentProvider: string;
attributes: {
isCancelled: boolean;
};
price: string;
period: PLAN_PERIOD;
}
export interface Plan {
id: string;
androidID: string;
iosID: string;
storage: number;
price: string;
period: PLAN_PERIOD;
stripeID: string;
}

View file

@ -0,0 +1,5 @@
export interface CastPayload {
collectionID: number;
collectionKey: string;
castToken: string;
}

View file

@ -1,168 +0,0 @@
import { Subscription } from 'types/billing';
export interface KeyAttributes {
kekSalt: string;
encryptedKey: string;
keyDecryptionNonce: string;
opsLimit: number;
memLimit: number;
publicKey: string;
encryptedSecretKey: string;
secretKeyDecryptionNonce: string;
masterKeyEncryptedWithRecoveryKey: string;
masterKeyDecryptionNonce: string;
recoveryKeyEncryptedWithMasterKey: string;
recoveryKeyDecryptionNonce: string;
}
export interface KEK {
key: string;
opsLimit: number;
memLimit: number;
}
export interface UpdatedKey {
kekSalt: string;
encryptedKey: string;
keyDecryptionNonce: string;
memLimit: number;
opsLimit: number;
}
export interface UpdateSRPAndKeysRequest {
srpM1: string;
setupID: string;
updatedKeyAttr: UpdatedKey;
}
export interface UpdateSRPAndKeysResponse {
srpM2: string;
setupID: string;
}
export interface RecoveryKey {
masterKeyEncryptedWithRecoveryKey: string;
masterKeyDecryptionNonce: string;
recoveryKeyEncryptedWithMasterKey: string;
recoveryKeyDecryptionNonce: string;
}
export interface User {
id: number;
email: string;
token: string;
encryptedToken: string;
isTwoFactorEnabled: boolean;
twoFactorSessionID: string;
}
export interface UserVerificationResponse {
id: number;
keyAttributes?: KeyAttributes;
encryptedToken?: string;
token?: string;
twoFactorSessionID: string;
srpM2?: string;
}
export interface TwoFactorVerificationResponse {
id: number;
keyAttributes: KeyAttributes;
encryptedToken?: string;
token?: string;
}
export interface TwoFactorSecret {
secretCode: string;
qrCode: string;
}
export interface TwoFactorRecoveryResponse {
encryptedSecret: string;
secretDecryptionNonce: string;
}
export interface FamilyMember {
email: string;
usage: number;
id: string;
isAdmin: boolean;
}
export interface FamilyData {
storage: number;
expiry: number;
members: FamilyMember[];
}
export interface UserDetails {
email: string;
usage: number;
fileCount: number;
sharedCollectionCount: number;
subscription: Subscription;
familyData?: FamilyData;
storageBonus?: number;
}
export interface DeleteChallengeResponse {
allowDelete: boolean;
encryptedChallenge: string;
}
export interface GetRemoteStoreValueResponse {
value: string;
}
export interface UpdateRemoteStoreValueRequest {
key: string;
value: string;
}
export interface SRPAttributes {
srpUserID: string;
srpSalt: string;
memLimit: number;
opsLimit: number;
kekSalt: string;
isEmailMFAEnabled: boolean;
}
export interface GetSRPAttributesResponse {
attributes: SRPAttributes;
}
export interface SRPSetupAttributes {
srpSalt: string;
srpVerifier: string;
srpUserID: string;
loginSubKey: string;
}
export interface SetupSRPRequest {
srpUserID: string;
srpSalt: string;
srpVerifier: string;
srpA: string;
}
export interface SetupSRPResponse {
setupID: string;
srpB: string;
}
export interface CompleteSRPSetupRequest {
setupID: string;
srpM1: string;
}
export interface CompleteSRPSetupResponse {
setupID: string;
srpM2: string;
}
export interface CreateSRPSessionResponse {
sessionID: string;
srpB: string;
}
export interface GetFeatureFlagResponse {
disableCFUploadProxy?: boolean;
}

View file

@ -12,9 +12,7 @@ import {
} from 'services/collectionService';
import { EnteFile } from 'types/file';
import { CustomError } from 'utils/error';
import { User } from 'types/user';
import { getData, LS_KEYS } from 'utils/storage/localStorage';
import { logError } from 'utils/sentry';
import { logError } from '@ente/shared/sentry';
import {
COLLECTION_ROLE,
Collection,
@ -38,6 +36,8 @@ import { isArchivedCollection, updateMagicMetadata } from 'utils/magicMetadata';
import bs58 from 'bs58';
import { t } from 'i18next';
import { getAlbumsURL } from '@ente/shared/network/api';
import { User } from '@ente/shared/user/types';
import { getData, LS_KEYS } from '@ente/shared/storage/localStorage';
// import { SetCollectionDownloadProgressAttributes } from 'types/gallery';
// import ElectronService from 'services/electron/common';
// import {

View file

@ -1,6 +1,6 @@
import { addLocalLog } from '@ente/shared/logging';
import { Remote, wrap } from 'comlink';
// import { WorkerElectronCacheStorageClient } from 'services/workerElectronCache/client';
import { addLocalLog } from 'utils/logging';
export class ComlinkWorker<T extends new () => InstanceType<T>> {
public remote: Promise<Remote<InstanceType<T>>>;

View file

@ -2,7 +2,7 @@ import { KeyAttributes, SRPSetupAttributes } from 'types/user';
import { SESSION_KEYS, setKey } from 'utils/storage/sessionStorage';
import { getData, LS_KEYS, setData } from 'utils/storage/localStorage';
import { setRecoveryKey } from 'services/userService';
import { logError } from 'utils/sentry';
import { logError } from '@ente/shared/sentry';
import isElectron from 'is-electron';
// import safeStorageService from 'services/electron/safeStorage';
import ComlinkCryptoWorker from 'utils/comlink/ComlinkCryptoWorker';

View file

@ -11,9 +11,7 @@ import {
import { decodeLivePhoto } from 'services/livePhotoService';
import { getFileType } from 'services/typeDetectionService';
import DownloadManager from 'services/downloadManager';
import { logError } from 'utils/sentry';
import { User } from 'types/user';
import { getData, LS_KEYS } from 'utils/storage/localStorage';
import { logError } from '@ente/shared/sentry';
import { updateFileCreationDateInEXIF } from 'services/upload/exifService';
import {
TYPE_JPEG,
@ -30,7 +28,6 @@ import * as ffmpegService from 'services/ffmpeg/ffmpegService';
import { VISIBILITY_STATE } from 'types/magicMetadata';
import { isArchivedFile, updateMagicMetadata } from 'utils/magicMetadata';
import { addLocalLog, addLogLine } from 'utils/logging';
import { CustomError } from 'utils/error';
import { convertBytesToHumanReadable } from './size';
import ComlinkCryptoWorker from 'utils/comlink/ComlinkCryptoWorker';
@ -45,6 +42,9 @@ import isElectron from 'is-electron';
import { isPlaybackPossible } from 'utils/photoFrame';
import { FileTypeInfo } from 'types/upload';
import { moveToHiddenCollection } from 'services/collectionService';
import { getData, LS_KEYS } from '@ente/shared/storage/localStorage';
import { User } from '@ente/shared/user/types';
import { addLogLine, addLocalLog } from '@ente/shared/logging';
// import ElectronFSService from 'services/electron/fs';
// import { getFileExportPath, getUniqueFileExportName } from 'utils/export';

View file

@ -1,116 +0,0 @@
import { ElectronFile } from 'types/upload';
import { convertBytesToHumanReadable } from 'utils/file/size';
import { formatDateTimeShort } from 'utils/time/format';
import { isDEVSentryENV } from 'constants/sentry';
import isElectron from 'is-electron';
// import ElectronService from 'services/electron/common';
import { logError } from 'utils/sentry';
import {
getData,
LS_KEYS,
removeData,
setData,
} from 'utils/storage/localStorage';
export const MAX_LOG_SIZE = 5 * 1024 * 1024; // 5MB
export const MAX_LOG_LINES = 1000;
export interface Log {
timestamp: number;
logLine: string;
}
export function addLogLine(
log: string | number | boolean,
...optionalParams: (string | number | boolean)[]
) {
try {
const completeLog = [log, ...optionalParams].join(' ');
if (isDEVSentryENV()) {
console.log(completeLog);
}
if (isElectron()) {
// ElectronService.logToDisk(completeLog);
} else {
saveLogLine({
timestamp: Date.now(),
logLine: completeLog,
});
}
} catch (e) {
if (e.name === 'QuotaExceededError') {
deleteLogs();
addLogLine('logs cleared');
}
logError(e, 'failed to addLogLine', undefined, true);
// ignore
}
}
export const addLocalLog = (getLog: () => string) => {
if (isDEVSentryENV()) {
console.log(getLog());
}
};
export function getDebugLogs() {
return combineLogLines(getLogs());
}
export function getFileNameSize(file: File | ElectronFile) {
return `${file.name}_${convertBytesToHumanReadable(file.size)}`;
}
export const clearLogsIfLocalStorageLimitExceeded = () => {
try {
const logs = getDebugLogs();
const logSize = getStringSize(logs);
if (logSize > MAX_LOG_SIZE) {
deleteLogs();
addLogLine('Logs cleared due to size limit exceeded');
} else {
try {
addLogLine(`app started`);
} catch (e) {
deleteLogs();
}
}
addLogLine(`logs size: ${convertBytesToHumanReadable(logSize)}`);
} catch (e) {
logError(e, 'failed to clearLogsIfLocalStorageLimitExceeded');
}
};
function saveLogLine(log: Log) {
const logs = getLogs();
if (logs.length > MAX_LOG_LINES) {
logs.slice(logs.length - MAX_LOG_LINES);
}
logs.push(log);
setLogs(logs);
}
function getLogs(): Log[] {
return getData(LS_KEYS.LOGS)?.logs ?? [];
}
function setLogs(logs: Log[]) {
setData(LS_KEYS.LOGS, { logs });
}
function deleteLogs() {
removeData(LS_KEYS.LOGS);
}
function getStringSize(str: string) {
return new Blob([str]).size;
}
function formatLog(log: Log) {
return `[${formatDateTimeShort(log.timestamp)}] ${log.logLine}`;
}
function combineLogLines(logs: Log[]) {
return logs.map(formatLog).join('\n');
}

View file

@ -1,167 +0,0 @@
import { FILE_TYPE } from 'constants/file';
import { Collection } from 'types/collection';
import { B64EncryptionResult, LocalFileAttributes } from 'types/crypto';
import {
MetadataFileAttributes,
S3FileAttributes,
FilePublicMagicMetadata,
FilePublicMagicMetadataProps,
} from 'types/file';
import { EncryptedMagicMetadata } from 'types/magicMetadata';
export interface DataStream {
stream: ReadableStream<Uint8Array>;
chunkCount: number;
}
export function isDataStream(object: any): object is DataStream {
return 'stream' in object;
}
export type Logger = (message: string) => void;
export interface Metadata {
title: string;
creationTime: number;
modificationTime: number;
latitude: number;
longitude: number;
fileType: FILE_TYPE;
hasStaticThumbnail?: boolean;
hash?: string;
imageHash?: string;
videoHash?: string;
localID?: number;
version?: number;
deviceFolder?: string;
}
export interface Location {
latitude: number;
longitude: number;
}
export interface ParsedMetadataJSON {
creationTime: number;
modificationTime: number;
latitude: number;
longitude: number;
}
export interface MultipartUploadURLs {
objectKey: string;
partURLs: string[];
completeURL: string;
}
export interface FileTypeInfo {
fileType: FILE_TYPE;
exactType: string;
mimeType?: string;
imageType?: string;
videoType?: string;
}
/*
* ElectronFile is a custom interface that is used to represent
* any file on disk as a File-like object in the Electron desktop app.
*
* This was added to support the auto-resuming of failed uploads
* which needed absolute paths to the files which the
* normal File interface does not provide.
*/
export interface ElectronFile {
name: string;
path: string;
size: number;
lastModified: number;
stream: () => Promise<ReadableStream<Uint8Array>>;
blob: () => Promise<Blob>;
arrayBuffer: () => Promise<Uint8Array>;
}
export interface UploadAsset {
isLivePhoto?: boolean;
file?: File | ElectronFile;
livePhotoAssets?: LivePhotoAssets;
isElectron?: boolean;
}
export interface LivePhotoAssets {
image: globalThis.File | ElectronFile;
video: globalThis.File | ElectronFile;
}
export interface FileWithCollection extends UploadAsset {
localID: number;
collection?: Collection;
collectionID?: number;
}
export type ParsedMetadataJSONMap = Map<string, ParsedMetadataJSON>;
export interface UploadURL {
url: string;
objectKey: string;
}
export interface FileInMemory {
filedata: Uint8Array | DataStream;
thumbnail: Uint8Array;
hasStaticThumbnail: boolean;
}
export interface FileWithMetadata
extends Omit<FileInMemory, 'hasStaticThumbnail'> {
metadata: Metadata;
localID: number;
pubMagicMetadata: FilePublicMagicMetadata;
}
export interface EncryptedFile {
file: ProcessedFile;
fileKey: B64EncryptionResult;
}
export interface ProcessedFile {
file: LocalFileAttributes<Uint8Array | DataStream>;
thumbnail: LocalFileAttributes<Uint8Array>;
metadata: LocalFileAttributes<string>;
pubMagicMetadata: EncryptedMagicMetadata;
localID: number;
}
export interface BackupedFile {
file: S3FileAttributes;
thumbnail: S3FileAttributes;
metadata: MetadataFileAttributes;
pubMagicMetadata: EncryptedMagicMetadata;
}
export interface UploadFile extends BackupedFile {
collectionID: number;
encryptedKey: string;
keyDecryptionNonce: string;
}
export interface ParsedExtractedMetadata {
location: Location;
creationTime: number;
width: number;
height: number;
}
// This is used to prompt the user the make upload strategy choice
export interface ImportSuggestion {
rootFolderName: string;
hasNestedFolders: boolean;
hasRootLevelFileWithFolder: boolean;
}
export interface PublicUploadProps {
token: string;
passwordToken: string;
accessedThroughSharedURL: boolean;
}
export interface ExtractMetadataResult {
metadata: Metadata;
publicMagicMetadata: FilePublicMagicMetadataProps;
}

View file

@ -1,43 +0,0 @@
import { UPLOAD_RESULT, UPLOAD_STAGES } from 'constants/upload';
export type FileID = number;
export type FileName = string;
export type PercentageUploaded = number;
export type UploadFileNames = Map<FileID, FileName>;
export interface UploadCounter {
finished: number;
total: number;
}
export interface InProgressUpload {
localFileID: FileID;
progress: PercentageUploaded;
}
export interface FinishedUpload {
localFileID: FileID;
result: UPLOAD_RESULT;
}
export type InProgressUploads = Map<FileID, PercentageUploaded>;
export type FinishedUploads = Map<FileID, UPLOAD_RESULT>;
export type SegregatedFinishedUploads = Map<UPLOAD_RESULT, FileID[]>;
export interface ProgressUpdater {
setPercentComplete: React.Dispatch<React.SetStateAction<number>>;
setUploadCounter: React.Dispatch<React.SetStateAction<UploadCounter>>;
setUploadStage: React.Dispatch<React.SetStateAction<UPLOAD_STAGES>>;
setInProgressUploads: React.Dispatch<
React.SetStateAction<InProgressUpload[]>
>;
setFinishedUploads: React.Dispatch<
React.SetStateAction<SegregatedFinishedUploads>
>;
setUploadFilenames: React.Dispatch<React.SetStateAction<UploadFileNames>>;
setHasLivePhotos: React.Dispatch<React.SetStateAction<boolean>>;
setUploadProgressView: React.Dispatch<React.SetStateAction<boolean>>;
}

View file

@ -1,7 +1,7 @@
import { FILE_TYPE } from 'constants/file';
import { EnteFile } from 'types/file';
import { MergedSourceURL } from 'types/gallery';
import { logError } from 'utils/sentry';
import { logError } from '@ente/shared/sentry';
const WAIT_FOR_VIDEO_PLAYBACK = 1 * 1000;

View file

@ -72,9 +72,9 @@ export default function AlbumCastDialog(props: Props) {
// ok, they exist. let's give them the good stuff.
const payload = JSON.stringify({
token: getToken(),
targetCollectionId: props.currentCollection.id,
targetCollectionKey: props.currentCollection.key,
castToken: getToken(),
collectionID: props.currentCollection.id,
collectionKey: props.currentCollection.key,
});
const encryptedPayload = await boxSeal(

View file

@ -3,9 +3,7 @@ import HTTPService from './HTTPService';
import { getEndpoint } from './api';
class CastGateway {
constructor() {
console.log('CastGateway');
}
constructor() {}
public async getCastData(code: string): Promise<string> {
let resp;