feat: use more @ente/shared

This commit is contained in:
httpjamesm 2024-01-06 00:08:33 -05:00
parent ca795906dd
commit f574d019f7
No known key found for this signature in database
13 changed files with 51 additions and 23 deletions

View file

@ -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<

View file

@ -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';

View file

@ -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();

View file

@ -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<

View file

@ -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();

View file

@ -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';

View file

@ -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 {

View file

@ -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>;

View file

@ -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'];

View file

@ -1,4 +1,4 @@
import { sleep } from 'utils/common';
import { sleep } from '@ente/shared/sleep';
const waitTimeBeforeNextAttemptInMilliSeconds = [2000, 5000, 10000];

View file

@ -1,5 +1,4 @@
import { runningInBrowser } from 'utils/common';
import { runningInBrowser } from '@ente/shared/apps/browser';
import localForage from 'localforage';
if (runningInBrowser()) {

View file

@ -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,
]);
};

View file

@ -0,0 +1,5 @@
export async function sleep(time: number) {
await new Promise((resolve) => {
setTimeout(() => resolve(null), time);
});
}