[cast] Switch to shared package import
This commit is contained in:
parent
cde75e3a37
commit
73885f6f0a
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
|
@ -11,7 +11,7 @@
|
||||||
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
||||||
"editor.formatOnPaste": true,
|
"editor.formatOnPaste": true,
|
||||||
"editor.codeActionsOnSave": {
|
"editor.codeActionsOnSave": {
|
||||||
"source.fixAll": true
|
"source.fixAll": "explicit"
|
||||||
},
|
},
|
||||||
"typescript.enablePromptUseWorkspaceTsdk": true
|
"typescript.enablePromptUseWorkspaceTsdk": true
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { getActualKey } from '@ente/shared/user';
|
import { getActualKey } from '@ente/shared/user';
|
||||||
import { batch } from '@ente/shared/batch';
|
import { batch } from '@ente/shared/batch';
|
||||||
import { EnteFile } from 'types/file';
|
import { EnteFile } from 'types/file';
|
||||||
import { CustomError } from 'utils/error';
|
import { CustomError } from '@ente/shared/error';
|
||||||
import {
|
import {
|
||||||
sortFiles,
|
sortFiles,
|
||||||
groupFilesBasedOnCollectionID,
|
groupFilesBasedOnCollectionID,
|
||||||
|
|
|
@ -6,7 +6,7 @@ import {
|
||||||
import { EnteFile } from 'types/file';
|
import { EnteFile } from 'types/file';
|
||||||
|
|
||||||
import { FILE_TYPE } from 'constants/file';
|
import { FILE_TYPE } from 'constants/file';
|
||||||
import { CustomError } from 'utils/error';
|
import { CustomError } from '@ente/shared/error';
|
||||||
import ComlinkCryptoWorker from 'utils/comlink/ComlinkCryptoWorker';
|
import ComlinkCryptoWorker from 'utils/comlink/ComlinkCryptoWorker';
|
||||||
import { CacheStorageService } from './cache/cacheStorageService';
|
import { CacheStorageService } from './cache/cacheStorageService';
|
||||||
import { CACHES } from 'constants/cache';
|
import { CACHES } from 'constants/cache';
|
||||||
|
|
|
@ -6,7 +6,7 @@ import {
|
||||||
import { EnteFile } from 'types/file';
|
import { EnteFile } from 'types/file';
|
||||||
|
|
||||||
import { FILE_TYPE } from 'constants/file';
|
import { FILE_TYPE } from 'constants/file';
|
||||||
import { CustomError } from 'utils/error';
|
import { CustomError } from '@ente/shared/error';
|
||||||
import ComlinkCryptoWorker from 'utils/comlink/ComlinkCryptoWorker';
|
import ComlinkCryptoWorker from 'utils/comlink/ComlinkCryptoWorker';
|
||||||
import { CACHES } from 'constants/cache';
|
import { CACHES } from 'constants/cache';
|
||||||
import { CacheStorageService } from './cache/cacheStorageService';
|
import { CacheStorageService } from './cache/cacheStorageService';
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { CustomError } from 'utils/error';
|
import { CustomError } from '@ente/shared/error';
|
||||||
|
|
||||||
interface RequestQueueItem {
|
interface RequestQueueItem {
|
||||||
request: (canceller?: RequestCanceller) => Promise<any>;
|
request: (canceller?: RequestCanceller) => Promise<any>;
|
||||||
|
|
|
@ -4,7 +4,7 @@ import {
|
||||||
WHITELISTED_FILE_FORMATS,
|
WHITELISTED_FILE_FORMATS,
|
||||||
KNOWN_NON_MEDIA_FORMATS,
|
KNOWN_NON_MEDIA_FORMATS,
|
||||||
} from 'constants/upload';
|
} from 'constants/upload';
|
||||||
import { CustomError } from 'utils/error';
|
import { CustomError } from '@ente/shared/error';
|
||||||
import { getFileExtension } from 'utils/file';
|
import { getFileExtension } from 'utils/file';
|
||||||
import { logError } from '@ente/shared/sentry';
|
import { logError } from '@ente/shared/sentry';
|
||||||
import { getUint8ArrayView } from './readerService';
|
import { getUint8ArrayView } from './readerService';
|
||||||
|
|
|
@ -5,7 +5,7 @@ import piexif from 'piexifjs';
|
||||||
import { FileTypeInfo } from 'types/upload';
|
import { FileTypeInfo } from 'types/upload';
|
||||||
import { logError } from '@ente/shared/sentry';
|
import { logError } from '@ente/shared/sentry';
|
||||||
import { validateAndGetCreationUnixTimeInMicroSeconds } from 'utils/time';
|
import { validateAndGetCreationUnixTimeInMicroSeconds } from 'utils/time';
|
||||||
import { CustomError } from 'utils/error';
|
import { CustomError } from '@ente/shared/error';
|
||||||
|
|
||||||
const EXIFR_UNSUPPORTED_FILE_FORMAT_MESSAGE = 'Unknown file format';
|
const EXIFR_UNSUPPORTED_FILE_FORMAT_MESSAGE = 'Unknown file format';
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import QueueProcessor from 'services/queueProcessor';
|
import QueueProcessor from 'services/queueProcessor';
|
||||||
import { CustomError } from 'utils/error';
|
|
||||||
import { retryAsyncFunction } from 'utils/network';
|
import { retryAsyncFunction } from 'utils/network';
|
||||||
import { DedicatedConvertWorker } from 'worker/convert.worker';
|
import { DedicatedConvertWorker } from 'worker/convert.worker';
|
||||||
import { ComlinkWorker } from 'utils/comlink/comlinkWorker';
|
import { ComlinkWorker } from 'utils/comlink/comlinkWorker';
|
||||||
|
@ -7,6 +6,7 @@ import { getDedicatedConvertWorker } from 'utils/comlink/ComlinkConvertWorker';
|
||||||
import { logError } from '@ente/shared/sentry';
|
import { logError } from '@ente/shared/sentry';
|
||||||
import { addLogLine } from '@ente/shared/logging';
|
import { addLogLine } from '@ente/shared/logging';
|
||||||
import { convertBytesToHumanReadable } from '@ente/shared/utils/size';
|
import { convertBytesToHumanReadable } from '@ente/shared/utils/size';
|
||||||
|
import { CustomError } from '@ente/shared/error';
|
||||||
|
|
||||||
const WORKER_POOL_SIZE = 2;
|
const WORKER_POOL_SIZE = 2;
|
||||||
const MAX_CONVERSION_IN_PARALLEL = 1;
|
const MAX_CONVERSION_IN_PARALLEL = 1;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import sodium, { StateAddress } from 'libsodium-wrappers';
|
import sodium, { StateAddress } from 'libsodium-wrappers';
|
||||||
import { ENCRYPTION_CHUNK_SIZE } from 'constants/crypto';
|
import { ENCRYPTION_CHUNK_SIZE } from 'constants/crypto';
|
||||||
import { B64EncryptionResult } from 'types/crypto';
|
import { B64EncryptionResult } from 'types/crypto';
|
||||||
import { CustomError } from 'utils/error';
|
import { CustomError } from '@ente/shared/error';
|
||||||
|
|
||||||
export async function decryptChaChaOneShot(
|
export async function decryptChaChaOneShot(
|
||||||
data: Uint8Array,
|
data: Uint8Array,
|
||||||
|
|
|
@ -1,17 +1,11 @@
|
||||||
import {
|
import {
|
||||||
addToCollection,
|
|
||||||
createAlbum,
|
createAlbum,
|
||||||
getNonEmptyCollections,
|
getNonEmptyCollections,
|
||||||
moveToCollection,
|
|
||||||
removeFromCollection,
|
|
||||||
restoreToCollection,
|
|
||||||
unhideToCollection,
|
|
||||||
updateCollectionMagicMetadata,
|
updateCollectionMagicMetadata,
|
||||||
updatePublicCollectionMagicMetadata,
|
updatePublicCollectionMagicMetadata,
|
||||||
updateSharedCollectionMagicMetadata,
|
updateSharedCollectionMagicMetadata,
|
||||||
} from 'services/collectionService';
|
} from 'services/collectionService';
|
||||||
import { EnteFile } from 'types/file';
|
import { EnteFile } from 'types/file';
|
||||||
import { CustomError } from 'utils/error';
|
|
||||||
import { logError } from '@ente/shared/sentry';
|
import { logError } from '@ente/shared/sentry';
|
||||||
import {
|
import {
|
||||||
COLLECTION_ROLE,
|
COLLECTION_ROLE,
|
||||||
|
@ -54,36 +48,6 @@ export enum COLLECTION_OPS_TYPE {
|
||||||
RESTORE,
|
RESTORE,
|
||||||
UNHIDE,
|
UNHIDE,
|
||||||
}
|
}
|
||||||
export async function handleCollectionOps(
|
|
||||||
type: COLLECTION_OPS_TYPE,
|
|
||||||
collection: Collection,
|
|
||||||
selectedFiles: EnteFile[],
|
|
||||||
selectedCollectionID: number
|
|
||||||
) {
|
|
||||||
switch (type) {
|
|
||||||
case COLLECTION_OPS_TYPE.ADD:
|
|
||||||
await addToCollection(collection, selectedFiles);
|
|
||||||
break;
|
|
||||||
case COLLECTION_OPS_TYPE.MOVE:
|
|
||||||
await moveToCollection(
|
|
||||||
selectedCollectionID,
|
|
||||||
collection,
|
|
||||||
selectedFiles
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
case COLLECTION_OPS_TYPE.REMOVE:
|
|
||||||
await removeFromCollection(collection.id, selectedFiles);
|
|
||||||
break;
|
|
||||||
case COLLECTION_OPS_TYPE.RESTORE:
|
|
||||||
await restoreToCollection(collection, selectedFiles);
|
|
||||||
break;
|
|
||||||
case COLLECTION_OPS_TYPE.UNHIDE:
|
|
||||||
await unhideToCollection(collection, selectedFiles);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw Error(CustomError.INVALID_COLLECTION_OPERATION);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getSelectedCollection(
|
export function getSelectedCollection(
|
||||||
collectionID: number,
|
collectionID: number,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import sodium, { StateAddress } from 'libsodium-wrappers';
|
import sodium, { StateAddress } from 'libsodium-wrappers';
|
||||||
import { ENCRYPTION_CHUNK_SIZE } from 'constants/crypto';
|
import { ENCRYPTION_CHUNK_SIZE } from 'constants/crypto';
|
||||||
import { B64EncryptionResult } from 'types/crypto';
|
import { B64EncryptionResult } from 'types/crypto';
|
||||||
import { CustomError } from 'utils/error';
|
import { CustomError } from '@ente/shared/error';
|
||||||
|
|
||||||
export async function decryptChaChaOneShot(
|
export async function decryptChaChaOneShot(
|
||||||
data: Uint8Array,
|
data: Uint8Array,
|
||||||
|
|
|
@ -1,163 +0,0 @@
|
||||||
import { HttpStatusCode } from 'axios';
|
|
||||||
|
|
||||||
export class ApiErrorResponse {
|
|
||||||
code: string;
|
|
||||||
message: string;
|
|
||||||
}
|
|
||||||
export class ApiError extends Error {
|
|
||||||
httpStatusCode: number;
|
|
||||||
errCode: string;
|
|
||||||
|
|
||||||
constructor(message: string, errCode: string, httpStatus: number) {
|
|
||||||
super(message);
|
|
||||||
this.name = 'ApiError';
|
|
||||||
this.errCode = errCode;
|
|
||||||
this.httpStatusCode = httpStatus;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function isApiErrorResponse(object: any): object is ApiErrorResponse {
|
|
||||||
return object && 'code' in object && 'message' in object;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const CustomError = {
|
|
||||||
THUMBNAIL_GENERATION_FAILED: 'thumbnail generation failed',
|
|
||||||
VIDEO_PLAYBACK_FAILED: 'video playback failed',
|
|
||||||
ETAG_MISSING: 'no header/etag present in response body',
|
|
||||||
KEY_MISSING: 'encrypted key missing from localStorage',
|
|
||||||
FAILED_TO_LOAD_WEB_WORKER: 'failed to load web worker',
|
|
||||||
CHUNK_MORE_THAN_EXPECTED: 'chunks more than expected',
|
|
||||||
CHUNK_LESS_THAN_EXPECTED: 'chunks less than expected',
|
|
||||||
UNSUPPORTED_FILE_FORMAT: 'unsupported file format',
|
|
||||||
FILE_TOO_LARGE: 'file too large',
|
|
||||||
SUBSCRIPTION_EXPIRED: 'subscription expired',
|
|
||||||
STORAGE_QUOTA_EXCEEDED: 'storage quota exceeded',
|
|
||||||
SESSION_EXPIRED: 'session expired',
|
|
||||||
INVALID_MIME_TYPE: (type: string) => `invalid mime type -${type}`,
|
|
||||||
SIGNUP_FAILED: 'signup failed',
|
|
||||||
FAV_COLLECTION_MISSING: 'favorite collection missing',
|
|
||||||
INVALID_COLLECTION_OPERATION: 'invalid collection operation',
|
|
||||||
TO_MOVE_FILES_FROM_MULTIPLE_COLLECTIONS:
|
|
||||||
'to move files from multiple collections',
|
|
||||||
WAIT_TIME_EXCEEDED: 'operation wait time exceeded',
|
|
||||||
REQUEST_CANCELLED: 'request canceled',
|
|
||||||
REQUEST_FAILED: 'request failed',
|
|
||||||
TOKEN_EXPIRED: 'token expired',
|
|
||||||
TOKEN_MISSING: 'token missing',
|
|
||||||
TOO_MANY_REQUESTS: 'too many requests',
|
|
||||||
BAD_REQUEST: 'bad request',
|
|
||||||
SUBSCRIPTION_NEEDED: 'subscription not present',
|
|
||||||
NOT_FOUND: 'not found ',
|
|
||||||
NO_METADATA: 'no metadata',
|
|
||||||
TOO_LARGE_LIVE_PHOTO_ASSETS: 'too large live photo assets',
|
|
||||||
NOT_A_DATE: 'not a date',
|
|
||||||
NOT_A_LOCATION: 'not a location',
|
|
||||||
FILE_ID_NOT_FOUND: 'file with id not found',
|
|
||||||
WEAK_DEVICE: 'password decryption failed on the device',
|
|
||||||
INCORRECT_PASSWORD: 'incorrect password',
|
|
||||||
UPLOAD_CANCELLED: 'upload cancelled',
|
|
||||||
REQUEST_TIMEOUT: 'request taking too long',
|
|
||||||
HIDDEN_COLLECTION_SYNC_FILE_ATTEMPTED:
|
|
||||||
'hidden collection sync file attempted',
|
|
||||||
UNKNOWN_ERROR: 'Something went wrong, please try again',
|
|
||||||
TYPE_DETECTION_FAILED: (fileFormat: string) =>
|
|
||||||
`type detection failed ${fileFormat}`,
|
|
||||||
WINDOWS_NATIVE_IMAGE_PROCESSING_NOT_SUPPORTED:
|
|
||||||
'Windows native image processing is not supported',
|
|
||||||
NETWORK_ERROR: 'Network Error',
|
|
||||||
NOT_FILE_OWNER: 'not file owner',
|
|
||||||
UPDATE_EXPORTED_RECORD_FAILED: 'update file exported record failed',
|
|
||||||
EXPORT_STOPPED: 'export stopped',
|
|
||||||
NO_EXPORT_FOLDER_SELECTED: 'no export folder selected',
|
|
||||||
EXPORT_FOLDER_DOES_NOT_EXIST: 'export folder does not exist',
|
|
||||||
NO_INTERNET_CONNECTION: 'no internet connection',
|
|
||||||
AUTH_KEY_NOT_FOUND: 'auth key not found',
|
|
||||||
EXIF_DATA_NOT_FOUND: 'exif data not found',
|
|
||||||
SELECT_FOLDER_ABORTED: 'select folder aborted',
|
|
||||||
NON_MEDIA_FILE: 'non media file',
|
|
||||||
NOT_AVAILABLE_ON_WEB: 'not available on web',
|
|
||||||
UNSUPPORTED_RAW_FORMAT: 'unsupported raw format',
|
|
||||||
NON_PREVIEWABLE_FILE: 'non previewable file',
|
|
||||||
PROCESSING_FAILED: 'processing failed',
|
|
||||||
EXPORT_RECORD_JSON_PARSING_FAILED: 'export record json parsing failed',
|
|
||||||
TWO_FACTOR_ENABLED: 'two factor enabled',
|
|
||||||
CLIENT_ERROR: 'client error',
|
|
||||||
ServerError: 'server error',
|
|
||||||
};
|
|
||||||
|
|
||||||
export function handleUploadError(error): Error {
|
|
||||||
const parsedError = parseUploadErrorCodes(error);
|
|
||||||
|
|
||||||
// breaking errors
|
|
||||||
switch (parsedError.message) {
|
|
||||||
case CustomError.SUBSCRIPTION_EXPIRED:
|
|
||||||
case CustomError.STORAGE_QUOTA_EXCEEDED:
|
|
||||||
case CustomError.SESSION_EXPIRED:
|
|
||||||
case CustomError.UPLOAD_CANCELLED:
|
|
||||||
throw parsedError;
|
|
||||||
}
|
|
||||||
return parsedError;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function errorWithContext(originalError: Error, context: string) {
|
|
||||||
const errorWithContext = new Error(context);
|
|
||||||
errorWithContext.stack =
|
|
||||||
errorWithContext.stack.split('\n').slice(2, 4).join('\n') +
|
|
||||||
'\n' +
|
|
||||||
originalError.stack;
|
|
||||||
return errorWithContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function parseUploadErrorCodes(error) {
|
|
||||||
let parsedMessage = null;
|
|
||||||
if (error instanceof ApiError) {
|
|
||||||
switch (error.httpStatusCode) {
|
|
||||||
case HttpStatusCode.PaymentRequired:
|
|
||||||
parsedMessage = CustomError.SUBSCRIPTION_EXPIRED;
|
|
||||||
break;
|
|
||||||
case HttpStatusCode.UpgradeRequired:
|
|
||||||
parsedMessage = CustomError.STORAGE_QUOTA_EXCEEDED;
|
|
||||||
break;
|
|
||||||
case HttpStatusCode.Unauthorized:
|
|
||||||
parsedMessage = CustomError.SESSION_EXPIRED;
|
|
||||||
break;
|
|
||||||
case HttpStatusCode.PayloadTooLarge:
|
|
||||||
parsedMessage = CustomError.FILE_TOO_LARGE;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
parsedMessage = `${CustomError.UNKNOWN_ERROR} statusCode:${error.httpStatusCode}`;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
parsedMessage = error.message;
|
|
||||||
}
|
|
||||||
return new Error(parsedMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
export const parseSharingErrorCodes = (error) => {
|
|
||||||
let parsedMessage = null;
|
|
||||||
if (error instanceof ApiError) {
|
|
||||||
switch (error.httpStatusCode) {
|
|
||||||
case HttpStatusCode.BadRequest:
|
|
||||||
parsedMessage = CustomError.BAD_REQUEST;
|
|
||||||
break;
|
|
||||||
case HttpStatusCode.PaymentRequired:
|
|
||||||
parsedMessage = CustomError.SUBSCRIPTION_NEEDED;
|
|
||||||
break;
|
|
||||||
case HttpStatusCode.NotFound:
|
|
||||||
parsedMessage = CustomError.NOT_FOUND;
|
|
||||||
break;
|
|
||||||
case HttpStatusCode.Unauthorized:
|
|
||||||
case HttpStatusCode.Gone:
|
|
||||||
parsedMessage = CustomError.TOKEN_EXPIRED;
|
|
||||||
break;
|
|
||||||
case HttpStatusCode.TooManyRequests:
|
|
||||||
parsedMessage = CustomError.TOO_MANY_REQUESTS;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
parsedMessage = `${CustomError.UNKNOWN_ERROR} statusCode:${error.httpStatusCode}`;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
parsedMessage = error.message;
|
|
||||||
}
|
|
||||||
return new Error(parsedMessage);
|
|
||||||
};
|
|
|
@ -28,7 +28,7 @@ import * as ffmpegService from 'services/ffmpeg/ffmpegService';
|
||||||
import { VISIBILITY_STATE } from 'types/magicMetadata';
|
import { VISIBILITY_STATE } from 'types/magicMetadata';
|
||||||
import { isArchivedFile, updateMagicMetadata } from 'utils/magicMetadata';
|
import { isArchivedFile, updateMagicMetadata } from 'utils/magicMetadata';
|
||||||
|
|
||||||
import { CustomError } from 'utils/error';
|
import { CustomError } from '@ente/shared/error';
|
||||||
import ComlinkCryptoWorker from 'utils/comlink/ComlinkCryptoWorker';
|
import ComlinkCryptoWorker from 'utils/comlink/ComlinkCryptoWorker';
|
||||||
import {
|
import {
|
||||||
deleteFromTrash,
|
deleteFromTrash,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import * as Comlink from 'comlink';
|
import * as Comlink from 'comlink';
|
||||||
import { StateAddress } from 'libsodium-wrappers';
|
import { StateAddress } from 'libsodium-wrappers';
|
||||||
import * as libsodium from 'utils/crypto/libsodium';
|
import * as libsodium from '@ente/shared/crypto/internal/libsodium';
|
||||||
|
|
||||||
const textDecoder = new TextDecoder();
|
const textDecoder = new TextDecoder();
|
||||||
const textEncoder = new TextEncoder();
|
const textEncoder = new TextEncoder();
|
||||||
|
|
Loading…
Reference in a new issue