π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
feat: use more @ente/shared
httpjamesmf574d019f7ba
diff --git a/apps/cast/src/services/downloadManager.ts b/apps/cast/src/services/downloadManager.tsindex b7d269e41d..e0c5437df2 100644--- a/apps/cast/src/services/downloadManager.ts+++ b/apps/cast/src/services/downloadManager.ts@@ -1,5 +1,3 @@-import { getToken } from 'utils/common/key';-import { getFileURL, getThumbnailURL } from 'utils/common/apiUtil';import {generateStreamFromArrayBuffer,getRenderableFileURL,@@ -19,6 +17,8 @@ import { DedicatedCryptoWorker } from 'worker/crypto.worker';import { LimitedCache } from 'types/cache';import { retryAsyncFunction } from 'utils/network';import { addLogLine } from 'utils/logging';+import { getToken } from '@ente/shared/storage/localStorage/helpers';+import { getFileURL, getThumbnailURL } from '@ente/shared/network/api';class DownloadManager {private fileObjectURLPromise = new Map<diff --git a/apps/cast/src/services/fileService.ts b/apps/cast/src/services/fileService.tsindex a39953ebcc..f223535a10 100644--- a/apps/cast/src/services/fileService.ts+++ b/apps/cast/src/services/fileService.ts@@ -1,7 +1,7 @@-import { getEndpoint } from 'utils/common/apiUtil';+import { getEndpoint } from '@ente/shared/network/api';import localForage from 'utils/storage/localForage';-import { getToken } from 'utils/common/key';+import { getToken } from '@ente/shared/storage/localStorage/helpers';import { Collection } from 'types/collection';import HTTPService from './HTTPService';import { logError } from 'utils/sentry';@@ -28,7 +28,7 @@ import {setCollectionLastSyncTime,} from './collectionService';import { REQUEST_BATCH_SIZE } from 'constants/api';-import { batch } from 'utils/common';+import { batch } from '@ente/shared/batch';const ENDPOINT = getEndpoint();const FILES_TABLE = 'files';diff --git a/apps/cast/src/services/kexService.ts b/apps/cast/src/services/kexService.tsindex 4183b3bfe0..bb45d14623 100644--- a/apps/cast/src/services/kexService.ts+++ b/apps/cast/src/services/kexService.ts@@ -1,6 +1,6 @@import { logError } from 'utils/sentry';import HTTPService from './HTTPService';-import { getEndpoint } from 'utils/common/apiUtil';+import { getEndpoint } from '@ente/shared/network/api';const ENDPOINT = getEndpoint();diff --git a/apps/cast/src/services/publicCollectionDownloadManager.ts b/apps/cast/src/services/publicCollectionDownloadManager.tsindex a5a19082c4..b38fbe0042 100644--- a/apps/cast/src/services/publicCollectionDownloadManager.ts+++ b/apps/cast/src/services/publicCollectionDownloadManager.ts@@ -1,7 +1,3 @@-import {- getPublicCollectionFileURL,- getPublicCollectionThumbnailURL,-} from 'utils/common/apiUtil';import {generateStreamFromArrayBuffer,getRenderableFileURL,@@ -17,6 +13,10 @@ import ComlinkCryptoWorker from 'utils/comlink/ComlinkCryptoWorker';import { CACHES } from 'constants/cache';import { CacheStorageService } from './cache/cacheStorageService';import { LimitedCache } from 'types/cache';+import {+ getPublicCollectionFileURL,+ getPublicCollectionThumbnailURL,+} from '@ente/shared/network/api';class PublicCollectionDownloadManager {private fileObjectURLPromise = new Map<diff --git a/apps/cast/src/services/userService.ts b/apps/cast/src/services/userService.tsindex b30012e0fa..15a93a80d9 100644--- a/apps/cast/src/services/userService.ts+++ b/apps/cast/src/services/userService.ts@@ -1,14 +1,9 @@import { PAGES } from 'constants/pages';-import {- getEndpoint,- getFamilyPortalURL,- isDevDeployment,-} from 'utils/common/apiUtil';import { clearKeys } from 'utils/storage/sessionStorage';import router from 'next/router';import { clearData, getData, LS_KEYS } from 'utils/storage/localStorage';import localForage from 'utils/storage/localForage';-import { getToken } from 'utils/common/key';+import { getToken } from '@ente/shared/storage/localStorage/helpers';import HTTPService from './HTTPService';import {computeVerifierHelper,@@ -52,6 +47,11 @@ import { addLocalLog } from 'utils/logging';import { convertBase64ToBuffer, convertBufferToBase64 } from 'utils/user';import { setLocalMapEnabled } from 'utils/storage';import InMemoryStore, { MS_KEYS } from './InMemoryStore';+import {+ getEndpoint,+ getFamilyPortalURL,+ isDevDeployment,+} from '@ente/shared/network/api';const ENDPOINT = getEndpoint();diff --git a/apps/cast/src/services/wasm/ffmpeg.ts b/apps/cast/src/services/wasm/ffmpeg.tsindex 37963652e4..fd2f207ab7 100644--- a/apps/cast/src/services/wasm/ffmpeg.ts+++ b/apps/cast/src/services/wasm/ffmpeg.ts@@ -1,7 +1,7 @@+import { promiseWithTimeout } from '@ente/shared/promise';import { createFFmpeg, FFmpeg } from 'ffmpeg-wasm';import QueueProcessor from 'services/queueProcessor';import { getUint8ArrayView } from 'services/readerService';-import { promiseWithTimeout } from 'utils/common';import { addLogLine } from 'utils/logging';import { logError } from 'utils/sentry';import { generateTempName } from 'utils/temp';diff --git a/apps/cast/src/utils/collection/index.ts b/apps/cast/src/utils/collection/index.tsindex 7c985d128d..08f50bf965 100644--- a/apps/cast/src/utils/collection/index.ts+++ b/apps/cast/src/utils/collection/index.ts@@ -35,9 +35,9 @@ import {import { getUnixTimeInMicroSecondsWithDelta } from 'utils/time';import { SUB_TYPE, VISIBILITY_STATE } from 'types/magicMetadata';import { isArchivedCollection, updateMagicMetadata } from 'utils/magicMetadata';-import { getAlbumsURL } from 'utils/common/apiUtil';import bs58 from 'bs58';import { t } from 'i18next';+import { getAlbumsURL } from '@ente/shared/network/api';// import { SetCollectionDownloadProgressAttributes } from 'types/gallery';// import ElectronService from 'services/electron/common';// import {diff --git a/apps/cast/src/utils/comlink/ComlinkConvertWorker.ts b/apps/cast/src/utils/comlink/ComlinkConvertWorker.tsindex c5a436728d..a55f2e6e49 100644--- a/apps/cast/src/utils/comlink/ComlinkConvertWorker.ts+++ b/apps/cast/src/utils/comlink/ComlinkConvertWorker.ts@@ -1,7 +1,7 @@import { Remote } from 'comlink';-import { runningInBrowser } from 'utils/common';import { DedicatedConvertWorker } from 'worker/convert.worker';import { ComlinkWorker } from './comlinkWorker';+import { runningInBrowser } from '@ente/shared/apps/browser';class ComlinkConvertWorker {private comlinkWorkerInstance: Remote<DedicatedConvertWorker>;diff --git a/apps/cast/src/utils/crypto/index.ts b/apps/cast/src/utils/crypto/index.tsindex c4ecd9fd14..ce1fb2fb0b 100644--- a/apps/cast/src/utils/crypto/index.ts+++ b/apps/cast/src/utils/crypto/index.ts@@ -1,7 +1,6 @@import { KeyAttributes, SRPSetupAttributes } from 'types/user';import { SESSION_KEYS, setKey } from 'utils/storage/sessionStorage';import { getData, LS_KEYS, setData } from 'utils/storage/localStorage';-import { getActualKey, getToken } from 'utils/common/key';import { setRecoveryKey } from 'services/userService';import { logError } from 'utils/sentry';import isElectron from 'is-electron';@@ -13,6 +12,8 @@ import { SRP, SrpClient } from 'fast-srp-hap';import { convertBase64ToBuffer, convertBufferToBase64 } from 'utils/user';import { v4 as uuidv4 } from 'uuid';import { addLocalLog } from 'utils/logging';+import { getActualKey } from '@ente/shared/user';+import { getToken } from '@ente/shared/storage/localStorage/helpers';const SRP_PARAMS = SRP.params['4096'];diff --git a/apps/cast/src/utils/network/index.ts b/apps/cast/src/utils/network/index.tsindex 832aa841dc..b0e017dd3c 100644--- a/apps/cast/src/utils/network/index.ts+++ b/apps/cast/src/utils/network/index.ts@@ -1,4 +1,4 @@-import { sleep } from 'utils/common';+import { sleep } from '@ente/shared/sleep';const waitTimeBeforeNextAttemptInMilliSeconds = [2000, 5000, 10000];diff --git a/apps/cast/src/utils/storage/localForage.ts b/apps/cast/src/utils/storage/localForage.tsindex b807318a61..10e98cd19e 100644--- a/apps/cast/src/utils/storage/localForage.ts+++ b/apps/cast/src/utils/storage/localForage.ts@@ -1,5 +1,4 @@-import { runningInBrowser } from 'utils/common';-+import { runningInBrowser } from '@ente/shared/apps/browser';import localForage from 'localforage';if (runningInBrowser()) {diff --git a/packages/shared/promise/index.ts b/packages/shared/promise/index.tsnew file mode 100644index 0000000000..849f18d94f--- /dev/null+++ b/packages/shared/promise/index.ts@@ -0,0 +1,23 @@+import { CustomError } from '../error';++export const promiseWithTimeout = async <T>(+ request: Promise<T>,+ timeout: number+): Promise<T> => {+ const timeoutRef = { current: null };+ const rejectOnTimeout = new Promise<null>((_, reject) => {+ timeoutRef.current = setTimeout(+ () => reject(Error(CustomError.WAIT_TIME_EXCEEDED)),+ timeout+ );+ });+ const requestWithTimeOutCancellation = async () => {+ const resp = await request;+ clearTimeout(timeoutRef.current);+ return resp;+ };+ return await Promise.race([+ requestWithTimeOutCancellation(),+ rejectOnTimeout,+ ]);+};diff --git a/packages/shared/sleep/index.ts b/packages/shared/sleep/index.tsnew file mode 100644index 0000000000..39e64cb5f5--- /dev/null+++ b/packages/shared/sleep/index.ts@@ -0,0 +1,5 @@+export async function sleep(time: number) {+ await new Promise((resolve) => {+ setTimeout(() => resolve(null), time);+ });+}