Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[cast] Switch to shared package import

Neeraj Gupta73885f6f0a2d
diff --git a/.vscode/settings.json b/.vscode/settings.json
index a56ae4a2e6..074e180a5d 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -11,7 +11,7 @@
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnPaste": true,
"editor.codeActionsOnSave": {
- "source.fixAll": true
+ "source.fixAll": "explicit"
},
"typescript.enablePromptUseWorkspaceTsdk": true
}
diff --git a/apps/cast/src/services/collectionService.ts b/apps/cast/src/services/collectionService.ts
index 9939c69f65..3e0c8c6c2c 100644
--- a/apps/cast/src/services/collectionService.ts
+++ b/apps/cast/src/services/collectionService.ts
@@ -1,7 +1,7 @@
import { getActualKey } from '@ente/shared/user';
import { batch } from '@ente/shared/batch';
import { EnteFile } from 'types/file';
-import { CustomError } from 'utils/error';
+import { CustomError } from '@ente/shared/error';
import {
sortFiles,
groupFilesBasedOnCollectionID,
diff --git a/apps/cast/src/services/downloadManager.ts b/apps/cast/src/services/downloadManager.ts
index ba9eef5aea..caa579e1bc 100644
--- a/apps/cast/src/services/downloadManager.ts
+++ b/apps/cast/src/services/downloadManager.ts
@@ -6,7 +6,7 @@ import {
import { EnteFile } from 'types/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 { CacheStorageService } from './cache/cacheStorageService';
import { CACHES } from 'constants/cache';
diff --git a/apps/cast/src/services/publicCollectionDownloadManager.ts b/apps/cast/src/services/publicCollectionDownloadManager.ts
index f679b8ab0b..5c5816ddd3 100644
--- a/apps/cast/src/services/publicCollectionDownloadManager.ts
+++ b/apps/cast/src/services/publicCollectionDownloadManager.ts
@@ -6,7 +6,7 @@ import {
import { EnteFile } from 'types/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 { CACHES } from 'constants/cache';
import { CacheStorageService } from './cache/cacheStorageService';
diff --git a/apps/cast/src/services/queueProcessor.ts b/apps/cast/src/services/queueProcessor.ts
index 6071556a15..97332aaee7 100644
--- a/apps/cast/src/services/queueProcessor.ts
+++ b/apps/cast/src/services/queueProcessor.ts
@@ -1,4 +1,4 @@
-import { CustomError } from 'utils/error';
+import { CustomError } from '@ente/shared/error';
interface RequestQueueItem {
request: (canceller?: RequestCanceller) => Promise<any>;
diff --git a/apps/cast/src/services/typeDetectionService.ts b/apps/cast/src/services/typeDetectionService.ts
index a9f254243c..49191ef20a 100644
--- a/apps/cast/src/services/typeDetectionService.ts
+++ b/apps/cast/src/services/typeDetectionService.ts
@@ -4,7 +4,7 @@ import {
WHITELISTED_FILE_FORMATS,
KNOWN_NON_MEDIA_FORMATS,
} from 'constants/upload';
-import { CustomError } from 'utils/error';
+import { CustomError } from '@ente/shared/error';
import { getFileExtension } from 'utils/file';
import { logError } from '@ente/shared/sentry';
import { getUint8ArrayView } from './readerService';
diff --git a/apps/cast/src/services/upload/exifService.ts b/apps/cast/src/services/upload/exifService.ts
index 92e18747bd..74dc48a5c9 100644
--- a/apps/cast/src/services/upload/exifService.ts
+++ b/apps/cast/src/services/upload/exifService.ts
@@ -5,7 +5,7 @@ import piexif from 'piexifjs';
import { FileTypeInfo } from 'types/upload';
import { logError } from '@ente/shared/sentry';
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';
diff --git a/apps/cast/src/services/wasmHeicConverter/wasmHEICConverterService.ts b/apps/cast/src/services/wasmHeicConverter/wasmHEICConverterService.ts
index 35c6652aab..a17884a9d4 100644
--- a/apps/cast/src/services/wasmHeicConverter/wasmHEICConverterService.ts
+++ b/apps/cast/src/services/wasmHeicConverter/wasmHEICConverterService.ts
@@ -1,5 +1,4 @@
import QueueProcessor from 'services/queueProcessor';
-import { CustomError } from 'utils/error';
import { retryAsyncFunction } from 'utils/network';
import { DedicatedConvertWorker } from 'worker/convert.worker';
import { ComlinkWorker } from 'utils/comlink/comlinkWorker';
@@ -7,6 +6,7 @@ import { getDedicatedConvertWorker } from 'utils/comlink/ComlinkConvertWorker';
import { logError } from '@ente/shared/sentry';
import { addLogLine } from '@ente/shared/logging';
import { convertBytesToHumanReadable } from '@ente/shared/utils/size';
+import { CustomError } from '@ente/shared/error';
const WORKER_POOL_SIZE = 2;
const MAX_CONVERSION_IN_PARALLEL = 1;
diff --git a/apps/cast/src/types/crypto/libsodium.ts b/apps/cast/src/types/crypto/libsodium.ts
index 958a2af0b7..02c12c8dfc 100644
--- a/apps/cast/src/types/crypto/libsodium.ts
+++ b/apps/cast/src/types/crypto/libsodium.ts
@@ -1,7 +1,7 @@
import sodium, { StateAddress } from 'libsodium-wrappers';
import { ENCRYPTION_CHUNK_SIZE } from 'constants/crypto';
import { B64EncryptionResult } from 'types/crypto';
-import { CustomError } from 'utils/error';
+import { CustomError } from '@ente/shared/error';
export async function decryptChaChaOneShot(
data: Uint8Array,
diff --git a/apps/cast/src/utils/collection/index.ts b/apps/cast/src/utils/collection/index.ts
index 981d3d1409..69d7cd7a68 100644
--- a/apps/cast/src/utils/collection/index.ts
+++ b/apps/cast/src/utils/collection/index.ts
@@ -1,17 +1,11 @@
import {
- addToCollection,
createAlbum,
getNonEmptyCollections,
- moveToCollection,
- removeFromCollection,
- restoreToCollection,
- unhideToCollection,
updateCollectionMagicMetadata,
updatePublicCollectionMagicMetadata,
updateSharedCollectionMagicMetadata,
} from 'services/collectionService';
import { EnteFile } from 'types/file';
-import { CustomError } from 'utils/error';
import { logError } from '@ente/shared/sentry';
import {
COLLECTION_ROLE,
@@ -54,36 +48,6 @@ export enum COLLECTION_OPS_TYPE {
RESTORE,
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(
collectionID: number,
diff --git a/apps/cast/src/utils/crypto/libsodium.ts b/apps/cast/src/utils/crypto/libsodium.ts
index 958a2af0b7..02c12c8dfc 100644
--- a/apps/cast/src/utils/crypto/libsodium.ts
+++ b/apps/cast/src/utils/crypto/libsodium.ts
@@ -1,7 +1,7 @@
import sodium, { StateAddress } from 'libsodium-wrappers';
import { ENCRYPTION_CHUNK_SIZE } from 'constants/crypto';
import { B64EncryptionResult } from 'types/crypto';
-import { CustomError } from 'utils/error';
+import { CustomError } from '@ente/shared/error';
export async function decryptChaChaOneShot(
data: Uint8Array,
diff --git a/apps/cast/src/utils/error/index.ts b/apps/cast/src/utils/error/index.ts
deleted file mode 100644
index 7a109b002c..0000000000
--- a/apps/cast/src/utils/error/index.ts
+++ /dev/null
@@ -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);
-};
diff --git a/apps/cast/src/utils/file/index.ts b/apps/cast/src/utils/file/index.ts
index e7b026d1b7..63936e6c9c 100644
--- a/apps/cast/src/utils/file/index.ts
+++ b/apps/cast/src/utils/file/index.ts
@@ -28,7 +28,7 @@ import * as ffmpegService from 'services/ffmpeg/ffmpegService';
import { VISIBILITY_STATE } from 'types/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 {
deleteFromTrash,
diff --git a/apps/cast/src/worker/crypto.worker.ts b/apps/cast/src/worker/crypto.worker.ts
index f6c63cc5d4..784c6e4ef2 100644
--- a/apps/cast/src/worker/crypto.worker.ts
+++ b/apps/cast/src/worker/crypto.worker.ts
@@ -1,6 +1,6 @@
import * as Comlink from 'comlink';
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 textEncoder = new TextEncoder();