Skip to content

armgit / ente

Public Imported from GitHub
0

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

Cont

Manav Rathi24b9e629c1c0
diff --git a/web/apps/photos/src/components/FixCreationTime.tsx b/web/apps/photos/src/components/FixCreationTime.tsx
index 91ea1ecb90..6bb9b16d43 100644
--- a/web/apps/photos/src/components/FixCreationTime.tsx
+++ b/web/apps/photos/src/components/FixCreationTime.tsx
@@ -12,7 +12,6 @@ import { FileType } from "@/media/file-type";
import { PhotoDateTimePicker } from "@/new/photos/components/PhotoDateTimePicker";
import downloadManager from "@/new/photos/services/download";
import { extractExifDates } from "@/new/photos/services/exif";
-import { ensure } from "@/utils/ensure";
import {
Box,
Dialog,
@@ -318,11 +317,11 @@ const updateEnteFileDate = async (
if (fixOption == "custom") {
newDate = {
- dateTime: ensure(customDate).dateTime,
+ dateTime: customDate!.dateTime,
// See [Note: Don't modify offsetTime when editing date via picker]
// for why we don't also set the offset here.
offset: undefined,
- timestamp: ensure(customDate).timestamp,
+ timestamp: customDate!.timestamp,
};
} else if (enteFile.metadata.fileType == FileType.image) {
const stream = await downloadManager.getFile(enteFile);
diff --git a/web/apps/photos/src/components/PhotoViewer/ImageEditorOverlay/index.tsx b/web/apps/photos/src/components/PhotoViewer/ImageEditorOverlay/index.tsx
index 248976a57b..c5aab81f81 100644
--- a/web/apps/photos/src/components/PhotoViewer/ImageEditorOverlay/index.tsx
+++ b/web/apps/photos/src/components/PhotoViewer/ImageEditorOverlay/index.tsx
@@ -12,7 +12,6 @@ import { EnteFile } from "@/media/file";
import { photosDialogZIndex } from "@/new/photos/components/utils/z-index";
import downloadManager from "@/new/photos/services/download";
import { AppContext } from "@/new/photos/types/context";
-import { ensure } from "@/utils/ensure";
import {
CenteredFlex,
HorizontalFlex,
@@ -453,7 +452,7 @@ const ImageEditorOverlay = (props: IProps) => {
}
const getEditedFile = async () => {
- const originalSizeCanvas = ensure(originalSizeCanvasRef.current);
+ const originalSizeCanvas = originalSizeCanvasRef.current!;
const originalFileName = props.file.metadata.title;
return canvasToFile(originalSizeCanvas, originalFileName, mimeType);
};
@@ -777,9 +776,9 @@ const canvasToFile = async (
break;
}
- const blob = ensure(
- await new Promise<Blob>((resolve) => canvas.toBlob(resolve, mimeType)),
- );
+ const blob = (await new Promise<Blob>((resolve) =>
+ canvas.toBlob(resolve, mimeType),
+ ))!;
const [originalName] = nameAndExtension(originalFileName);
const fileName = `${originalName}-edited.${extension}`;
diff --git a/web/apps/photos/src/components/Upload/Uploader.tsx b/web/apps/photos/src/components/Upload/Uploader.tsx
index 7b0e0e2378..e5acb2f6d4 100644
--- a/web/apps/photos/src/components/Upload/Uploader.tsx
+++ b/web/apps/photos/src/components/Upload/Uploader.tsx
@@ -18,7 +18,6 @@ import { redirectToCustomerPortal } from "@/new/photos/services/user-details";
import { useAppContext } from "@/new/photos/types/context";
import { NotificationAttributes } from "@/new/photos/types/notification";
import { firstNonEmpty } from "@/utils/array";
-import { ensure } from "@/utils/ensure";
import { CustomError } from "@ente/shared/error";
import DiscFullIcon from "@mui/icons-material/DiscFull";
import InfoOutlined from "@mui/icons-material/InfoRounded";
@@ -853,17 +852,13 @@ const desktopFilesAndZipItems = async (electron: Electron, files: File[]) => {
* https://github.com/react-dropzone/file-selector/blob/master/src/file.ts#L1214
*/
const pathLikeForWebFile = (file: File): string =>
- ensure(
- firstNonEmpty([
- // We need to check first, since path is not a property of
- // the standard File objects.
- "path" in file && typeof file.path == "string"
- ? file.path
- : undefined,
- file.webkitRelativePath,
- file.name,
- ]),
- );
+ firstNonEmpty([
+ // We need to check first, since path is not a property of
+ // the standard File objects.
+ "path" in file && typeof file.path == "string" ? file.path : undefined,
+ file.webkitRelativePath,
+ file.name,
+ ])!;
// This is used to prompt the user the make upload strategy choice
interface ImportSuggestion {
@@ -889,7 +884,7 @@ function getImportSuggestion(
const separatorCounts = new Map(
paths.map((s) => [s, s.match(/\//g)?.length ?? 0]),
);
- const separatorCount = (s: string) => ensure(separatorCounts.get(s));
+ const separatorCount = (s: string) => separatorCounts.get(s)!;
paths.sort((path1, path2) => separatorCount(path1) - separatorCount(path2));
const firstPath = paths[0];
const lastPath = paths[paths.length - 1];
diff --git a/web/apps/photos/src/components/WatchFolder.tsx b/web/apps/photos/src/components/WatchFolder.tsx
index 0446509b2e..f8b75086ee 100644
--- a/web/apps/photos/src/components/WatchFolder.tsx
+++ b/web/apps/photos/src/components/WatchFolder.tsx
@@ -9,7 +9,6 @@ import type { CollectionMapping, FolderWatch } from "@/base/types/ipc";
import { CollectionMappingChoiceDialog } from "@/new/photos/components/CollectionMappingChoiceDialog";
import { DialogCloseIconButton } from "@/new/photos/components/mui/Dialog";
import { AppContext, useAppContext } from "@/new/photos/types/context";
-import { ensure } from "@/utils/ensure";
import {
FlexWrapper,
HorizontalFlex,
@@ -109,7 +108,7 @@ export const WatchFolder: React.FC<ModalVisibilityProps> = ({
const handleCollectionMappingSelect = (mapping: CollectionMapping) => {
setSavedFolderPath(undefined);
- addWatch(ensure(savedFolderPath), mapping);
+ addWatch(savedFolderPath!, mapping);
};
return (
diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsx
index f6deba1397..e929aa6707 100644
--- a/web/apps/photos/src/pages/gallery.tsx
+++ b/web/apps/photos/src/pages/gallery.tsx
@@ -55,7 +55,6 @@ import {
} from "@/new/photos/services/user-details";
import { useAppContext } from "@/new/photos/types/context";
import { splitByPredicate } from "@/utils/array";
-import { ensure } from "@/utils/ensure";
import {
CenteredFlex,
FlexWrapper,
@@ -512,7 +511,7 @@ export default function Gallery() {
}
: {
mode: barMode as "albums" | "hidden-albums",
- collectionID: ensure(activeCollectionID),
+ collectionID: activeCollectionID!,
},
};
diff --git a/web/apps/photos/src/services/upload/thumbnail.ts b/web/apps/photos/src/services/upload/thumbnail.ts
index a768a04622..281a91fa52 100644
--- a/web/apps/photos/src/services/upload/thumbnail.ts
+++ b/web/apps/photos/src/services/upload/thumbnail.ts
@@ -8,7 +8,6 @@ import {
toDataOrPathOrZipEntry,
type DesktopUploadItem,
} from "@/new/photos/services/upload/types";
-import { ensure } from "@/utils/ensure";
import { withTimeout } from "@/utils/promise";
/** Maximum width or height of the generated thumbnail */
@@ -70,7 +69,7 @@ const generateImageThumbnailWeb = async (
const generateImageThumbnailUsingCanvas = async (blob: Blob) => {
const canvas = document.createElement("canvas");
- const canvasCtx = ensure(canvas.getContext("2d"));
+ const canvasCtx = canvas.getContext("2d")!;
const imageURL = URL.createObjectURL(blob);
await withTimeout(
@@ -118,7 +117,7 @@ const compressedJPEGData = async (canvas: HTMLCanvasElement) => {
percentageSizeDiff(blob.size, prevSize) >= 10
);
- return new Uint8Array(await ensure(blob).arrayBuffer());
+ return new Uint8Array(await blob!.arrayBuffer());
};
const percentageSizeDiff = (
@@ -140,7 +139,7 @@ const generateVideoThumbnailWeb = async (blob: Blob) => {
export const generateVideoThumbnailUsingCanvas = async (blob: Blob) => {
const canvas = document.createElement("canvas");
- const canvasCtx = ensure(canvas.getContext("2d"));
+ const canvasCtx = canvas.getContext("2d")!;
const videoURL = URL.createObjectURL(blob);
await withTimeout(
diff --git a/web/apps/photos/src/services/upload/uploadManager.ts b/web/apps/photos/src/services/upload/uploadManager.ts
index 12ddef9ee2..cb733f7a5c 100644
--- a/web/apps/photos/src/services/upload/uploadManager.ts
+++ b/web/apps/photos/src/services/upload/uploadManager.ts
@@ -18,7 +18,6 @@ import {
UPLOAD_RESULT,
type UploadPhase,
} from "@/new/photos/services/upload/types";
-import { ensure } from "@/utils/ensure";
import { wait } from "@/utils/promise";
import { CustomError } from "@ente/shared/error";
import { Canceler } from "axios";
@@ -514,9 +513,7 @@ class UploadManager {
this.abortIfCancelled();
log.info(`Parsing metadata JSON ${fileName}`);
- const metadataJSON = await tryParseTakeoutMetadataJSON(
- ensure(uploadItem),
- );
+ const metadataJSON = await tryParseTakeoutMetadataJSON(uploadItem!);
if (metadataJSON) {
this.parsedMetadataJSONMap.set(
getMetadataJSONMapKeyForJSON(collectionID, fileName),
@@ -757,13 +754,11 @@ type UploadItemWithCollectionIDAndName = UploadAsset & {
const makeUploadItemWithCollectionIDAndName = (
f: UploadItemWithCollection,
): UploadItemWithCollectionIDAndName => ({
- localID: ensure(f.localID),
- collectionID: ensure(f.collectionID),
- fileName: ensure(
- f.isLivePhoto
- ? uploadItemFileName(f.livePhotoAssets.image)
- : uploadItemFileName(f.uploadItem),
- ),
+ localID: f.localID!,
+ collectionID: f.collectionID!,
+ fileName: (f.isLivePhoto
+ ? uploadItemFileName(f.livePhotoAssets.image)
+ : uploadItemFileName(f.uploadItem))!,
isLivePhoto: f.isLivePhoto,
uploadItem: f.uploadItem,
livePhotoAssets: f.livePhotoAssets,
@@ -835,7 +830,7 @@ const markUploaded = async (electron: Electron, item: ClusteredUploadItem) => {
);
}
} else {
- const p = ensure(item.uploadItem);
+ const p = item.uploadItem!;
if (Array.isArray(p)) {
electron.markUploadedZipItems([p]);
} else if (typeof p == "string") {
diff --git a/web/apps/photos/src/utils/photoFrame/index.ts b/web/apps/photos/src/utils/photoFrame/index.ts
index 651848f1d9..3665478a05 100644
--- a/web/apps/photos/src/utils/photoFrame/index.ts
+++ b/web/apps/photos/src/utils/photoFrame/index.ts
@@ -4,7 +4,6 @@ import { EnteFile } from "@/media/file";
import { FileType } from "@/media/file-type";
import type { SelectionContext } from "@/new/photos/components/gallery";
import type { GalleryBarMode } from "@/new/photos/components/gallery/reducer";
-import { ensure } from "@/utils/ensure";
import { SetSelectedState } from "types/gallery";
export async function playVideo(livePhotoVideo, livePhotoImage) {
@@ -137,10 +136,10 @@ export const handleSelectCreator =
...selected,
context:
mode == "people"
- ? { mode, personID: ensure(activePersonID) }
+ ? { mode, personID: activePersonID! }
: {
mode,
- collectionID: ensure(activeCollectionID),
+ collectionID: activeCollectionID!,
},
};
} else {
@@ -153,10 +152,10 @@ export const handleSelectCreator =
collectionID: 0,
context:
mode == "people"
- ? { mode, personID: ensure(activePersonID) }
+ ? { mode, personID: activePersonID! }
: {
mode,
- collectionID: ensure(activeCollectionID),
+ collectionID: activeCollectionID!,
},
};
} else {
diff --git a/web/packages/accounts/components/RecoveryKey.tsx b/web/packages/accounts/components/RecoveryKey.tsx
index 3b26ff969c..ba5e4f4e64 100644
--- a/web/packages/accounts/components/RecoveryKey.tsx
+++ b/web/packages/accounts/components/RecoveryKey.tsx
@@ -7,7 +7,6 @@ import { useIsSmallWidth } from "@/base/hooks";
import log from "@/base/log";
import { downloadString } from "@/base/utils/web";
import { DialogCloseIconButton } from "@/new/photos/components/mui/Dialog";
-import { ensure } from "@/utils/ensure";
import CodeBlock from "@ente/shared/components/CodeBlock";
import { getRecoveryKey } from "@ente/shared/crypto/helpers";
import {
@@ -58,7 +57,7 @@ export const RecoveryKey: React.FC<RecoveryKeyProps> = ({
}, [open, handleLoadError]);
const handleSaveClick = () => {
- downloadRecoveryKeyMnemonic(ensure(recoveryKey));
+ downloadRecoveryKeyMnemonic(recoveryKey!);
onClose();
};
diff --git a/web/packages/accounts/pages/change-email.tsx b/web/packages/accounts/pages/change-email.tsx
index f60f96f6d0..94b182e01a 100644
--- a/web/packages/accounts/pages/change-email.tsx
+++ b/web/packages/accounts/pages/change-email.tsx
@@ -5,7 +5,6 @@ import {
FormPaperTitle,
} from "@/base/components/FormPaper";
import { LoadingButton } from "@/base/components/mui/LoadingButton";
-import { ensure } from "@/utils/ensure";
import { VerticallyCentered } from "@ente/shared/components/Container";
import LinkButton from "@ente/shared/components/LinkButton";
import { LS_KEYS, getData, setLSUser } from "@ente/shared/storage/localStorage";
@@ -81,7 +80,7 @@ const ChangeEmailForm: React.FC = () => {
) => {
try {
setLoading(true);
- await changeEmail(email, ensure(ott));
+ await changeEmail(email, ott!);
await setLSUser({ ...getData(LS_KEYS.USER), email });
setLoading(false);
goToApp();
diff --git a/web/packages/accounts/pages/change-password.tsx b/web/packages/accounts/pages/change-password.tsx
index a8750be29f..54870dcd3c 100644
--- a/web/packages/accounts/pages/change-password.tsx
+++ b/web/packages/accounts/pages/change-password.tsx
@@ -19,7 +19,6 @@ import {
FormPaperTitle,
} from "@/base/components/FormPaper";
import { sharedCryptoWorker } from "@/base/crypto";
-import { ensure } from "@/utils/ensure";
import { VerticallyCentered } from "@ente/shared/components/Container";
import LinkButton from "@ente/shared/components/LinkButton";
import {
@@ -94,7 +93,7 @@ const Page: React.FC<PageProps> = () => {
const srpA = convertBufferToBase64(srpClient.computeA());
- const { setupID, srpB } = await startSRPSetup(ensure(token), {
+ const { setupID, srpB } = await startSRPSetup(token!, {
srpUserID,
srpSalt,
srpVerifier,
@@ -105,7 +104,7 @@ const Page: React.FC<PageProps> = () => {
const srpM1 = convertBufferToBase64(srpClient.computeM1());
- await updateSRPAndKeys(ensure(token), {
+ await updateSRPAndKeys(token!, {
setupID,
srpM1,
updatedKeyAttr: updatedKey,
diff --git a/web/packages/accounts/services/passkey.ts b/web/packages/accounts/services/passkey.ts
index ac68f470b0..a15b5ec0a9 100644
--- a/web/packages/accounts/services/passkey.ts
+++ b/web/packages/accounts/services/passkey.ts
@@ -5,7 +5,6 @@ import { clientPackageHeader, HTTPError } from "@/base/http";
import log from "@/base/log";
import { accountsAppOrigin, apiURL } from "@/base/origins";
import { TwoFactorAuthorizationResponse } from "@/base/types/credentials";
-import { ensure } from "@/utils/ensure";
import { getRecoveryKey } from "@ente/shared/crypto/helpers";
import HTTPService from "@ente/shared/network/HTTPService";
import {
@@ -263,7 +262,7 @@ export const saveCredentialsAndNavigateTo = async (
encryptedToken,
id,
});
- setData(LS_KEYS.KEY_ATTRIBUTES, ensure(keyAttributes));
+ setData(LS_KEYS.KEY_ATTRIBUTES, keyAttributes!);
return unstashRedirect() ?? "/credentials";
};
diff --git a/web/packages/accounts/services/session.ts b/web/packages/accounts/services/session.ts
index 77389e6d02..0830ab923b 100644
--- a/web/packages/accounts/services/session.ts
+++ b/web/packages/accounts/services/session.ts
@@ -1,7 +1,6 @@
import { authenticatedRequestHeaders, HTTPError } from "@/base/http";
import { ensureLocalUser } from "@/base/local-user";
import { apiURL } from "@/base/origins";
-import { ensure } from "@/utils/ensure";
import { getData, LS_KEYS } from "@ente/shared/storage/localStorage";
import type { KeyAttributes } from "@ente/shared/user/types";
import type { SRPAttributes } from "../api/srp";
@@ -86,7 +85,7 @@ export const checkSessionValidity = async (): Promise<SessionValidity> => {
// We should have these values locally if we reach here.
const email = ensureLocalUser().email;
- const localSRPAttributes = ensure(getData(LS_KEYS.SRP_ATTRIBUTES));
+ const localSRPAttributes = getData(LS_KEYS.SRP_ATTRIBUTES)!;
// Fetch the remote SRP attributes.
//
diff --git a/web/packages/new/photos/components/CollectionSelector.tsx b/web/packages/new/photos/components/CollectionSelector.tsx
index 3619b3ab0a..cbbdec0311 100644
--- a/web/packages/new/photos/components/CollectionSelector.tsx
+++ b/web/packages/new/photos/components/CollectionSelector.tsx
@@ -14,7 +14,6 @@ import {
type CollectionSummaries,
type CollectionSummary,
} from "@/new/photos/services/collection/ui";
-import { ensure } from "@/utils/ensure";
import {
Dialog,
DialogContent,
@@ -126,8 +125,8 @@ export const CollectionSelector: React.FC<CollectionSelectorProps> = ({
})
.sort((a, b) => {
return (
- ensure(CollectionSummaryOrder.get(a.type)) -
- ensure(CollectionSummaryOrder.get(b.type))
+ CollectionSummaryOrder.get(a.type)! -
+ CollectionSummaryOrder.get(b.type)!
);
});
diff --git a/web/packages/new/photos/components/PlanSelector.tsx b/web/packages/new/photos/components/PlanSelector.tsx
index 5f8061897f..5d43857d60 100644
--- a/web/packages/new/photos/components/PlanSelector.tsx
+++ b/web/packages/new/photos/components/PlanSelector.tsx
@@ -32,7 +32,6 @@ import {
import { useAppContext } from "@/new/photos/types/context";
import { bytesInGB, formattedStorageByteSize } from "@/new/photos/utils/units";
import { openURL } from "@/new/photos/utils/web";
-import { ensure } from "@/utils/ensure";
import {
FlexWrapper,
FluidContainer,
@@ -158,7 +157,7 @@ const PlanSelectorCard: React.FC<PlanSelectorCardProps> = ({
case "buyPlan":
try {
setLoading(true);
- await redirectToPaymentsApp(ensure(plan.stripeID), "buy");
+ await redirectToPaymentsApp(plan.stripeID!, "buy");
} catch (e) {
setLoading(false);
showMiniDialog(
@@ -176,10 +175,7 @@ const PlanSelectorCard: React.FC<PlanSelectorCardProps> = ({
continue: {
text: t("update_subscription"),
action: () =>
- redirectToPaymentsApp(
- ensure(plan.stripeID),
- "update",
- ),
+ redirectToPaymentsApp(plan.stripeID!, "update"),
},
});
break;
diff --git a/web/packages/new/photos/components/gallery/BarImpl.tsx b/web/packages/new/photos/components/gallery/BarImpl.tsx
index 29c9d7987c..7d4875f32c 100644
--- a/web/packages/new/photos/components/gallery/BarImpl.tsx
+++ b/web/packages/new/photos/components/gallery/BarImpl.tsx
@@ -18,7 +18,6 @@ import type {
CollectionsSortBy,
} from "@/new/photos/services/collection/ui";
import type { Person } from "@/new/photos/services/ml/people";
-import { ensure } from "@/utils/ensure";
import ArchiveIcon from "@mui/icons-material/Archive";
import ExpandMore from "@mui/icons-material/ExpandMore";
import Favorite from "@mui/icons-material/FavoriteRounded";
@@ -201,7 +200,7 @@ export const GalleryBarImpl: React.FC<GalleryBarImplProps> = ({
? {
type: "collections",
collectionSummaries,
- activeCollectionID: ensure(activeCollectionID),
+ activeCollectionID: activeCollectionID!,
onSelectCollectionID,
}
: {
@@ -439,11 +438,11 @@ const getItemCount = (data: ItemData) => {
const getItemKey = (index: number, data: ItemData) => {
switch (data.type) {
case "collections": {
- const collectionSummary = ensure(data.collectionSummaries[index]);
+ const collectionSummary = data.collectionSummaries[index]!;
return `${data.type}-${collectionSummary.id}-${collectionSummary.coverFile?.id}`;
}
case "people": {
- const person = ensure(data.people[index]);
+ const person = data.people[index]!;
return `${data.type}-${person.id}-${person.displayFaceID}`;
}
}
@@ -461,7 +460,7 @@ const ListItem = memo((props: ListChildComponentProps<ItemData>) => {
activeCollectionID,
onSelectCollectionID,
} = data;
- const collectionSummary = ensure(collectionSummaries[index]);
+ const collectionSummary = collectionSummaries[index]!;
card = (
<CollectionBarCard
key={collectionSummary.id}
@@ -477,7 +476,7 @@ const ListItem = memo((props: ListChildComponentProps<ItemData>) => {
case "people": {
const { people, activePerson, onSelectPerson } = data;
- const person = ensure(people[index]);
+ const person = people[index]!;
card = (
<PersonCard
key={person.id}
diff --git a/web/packages/new/photos/components/gallery/reducer.ts b/web/packages/new/photos/components/gallery/reducer.ts
index 7bd98fda94..c8b0676ed1 100644
--- a/web/packages/new/photos/components/gallery/reducer.ts
+++ b/web/packages/new/photos/components/gallery/reducer.ts
@@ -10,7 +10,6 @@ import {
isHiddenCollection,
} from "@/new/photos/services/collection";
import { splitByPredicate } from "@/utils/array";
-import { ensure } from "@/utils/ensure";
import type { User } from "@ente/shared/user/types";
import { t } from "i18next";
import React, { useReducer } from "react";
@@ -436,7 +435,7 @@ const galleryReducer: React.Reducer<GalleryState, GalleryAction> = (
action.collections.concat(state.hiddenCollections),
),
collectionSummaries: deriveCollectionSummaries(
- ensure(state.user),
+ state.user!,
action.collections,
state.files,
state.trashedFiles,
@@ -464,14 +463,14 @@ const galleryReducer: React.Reducer<GalleryState, GalleryAction> = (
action.collections.concat(action.hiddenCollections),
),
collectionSummaries: deriveCollectionSummaries(
- ensure(state.user),
+ state.user!,
action.collections,
state.files,
state.trashedFiles,
archivedCollectionIDs,
),
hiddenCollectionSummaries: deriveHiddenCollectionSummaries(
- ensure(state.user),
+ state.user!,
action.hiddenCollections,
state.hiddenFiles,
),
@@ -488,7 +487,7 @@ const galleryReducer: React.Reducer<GalleryState, GalleryAction> = (
),
fileCollectionIDs: createFileCollectionIDs(action.files),
collectionSummaries: deriveCollectionSummaries(
- ensure(state.user),
+ state.user!,
state.collections,
files,
state.trashedFiles,
@@ -511,7 +510,7 @@ const galleryReducer: React.Reducer<GalleryState, GalleryAction> = (
),
fileCollectionIDs: createFileCollectionIDs(action.files),
collectionSummaries: deriveCollectionSummaries(
- ensure(state.user),
+ state.user!,
state.collections,
files,
state.trashedFiles,
@@ -532,7 +531,7 @@ const galleryReducer: React.Reducer<GalleryState, GalleryAction> = (
// TODO: Consider batching this instead of doing it per file
// upload to speed up uploads. Perf test first though.
collectionSummaries: deriveCollectionSummaries(
- ensure(state.user),
+ state.user!,
state.collections,
files,
state.trashedFiles,
@@ -547,7 +546,7 @@ const galleryReducer: React.Reducer<GalleryState, GalleryAction> = (
hiddenFiles,
hiddenFileIDs: deriveHiddenFileIDs(hiddenFiles),
hiddenCollectionSummaries: deriveHiddenCollectionSummaries(
- ensure(state.user),
+ state.user!,
state.hiddenCollections,
hiddenFiles,
),
@@ -567,7 +566,7 @@ const galleryReducer: React.Reducer<GalleryState, GalleryAction> = (
hiddenFiles,
hiddenFileIDs: deriveHiddenFileIDs(hiddenFiles),
hiddenCollectionSummaries: deriveHiddenCollectionSummaries(
- ensure(state.user),
+ state.user!,
state.hiddenCollections,
hiddenFiles,
),
@@ -578,7 +577,7 @@ const galleryReducer: React.Reducer<GalleryState, GalleryAction> = (
...state,
trashedFiles: action.trashedFiles,
collectionSummaries: deriveCollectionSummaries(
- ensure(state.user),
+ state.user!,
state.collections,
state.files,
action.trashedFiles,
diff --git a/web/packages/new/photos/services/download.ts b/web/packages/new/photos/services/download.ts
index 2da7a4c5e7..5973c5f0ff 100644
--- a/web/packages/new/photos/services/download.ts
+++ b/web/packages/new/photos/services/download.ts
@@ -12,7 +12,6 @@ import { FileType } from "@/media/file-type";
import { decodeLivePhoto } from "@/media/live-photo";
import * as ffmpeg from "@/new/photos/services/ffmpeg";
import { renderableImageBlob } from "@/new/photos/utils/file";
-import { ensure } from "@/utils/ensure";
import { CustomError } from "@ente/shared/error";
import HTTPService from "@ente/shared/network/HTTPService";
import { retryAsyncFunction } from "@ente/shared/utils";
@@ -90,8 +89,8 @@ class DownloadManagerImpl {
);
return {
- downloadClient: ensure(this.downloadClient),
- cryptoWorker: ensure(this.cryptoWorker),
+ downloadClient: this.downloadClient!,
+ cryptoWorker: this.cryptoWorker!,
};
}
@@ -200,9 +199,8 @@ class DownloadManagerImpl {
// TODO: Is this ensure valid?
// The existing code was already dereferencing, so it shouldn't
// affect behaviour.
- const { url: originalFileURL } = ensure(
- await this.fileObjectURLPromises.get(file.id),
- );
+ const { url: originalFileURL } =
+ (await this.fileObjectURLPromises.get(file.id))!;
const converted = await getRenderableFileURL(
file,
@@ -255,9 +253,7 @@ class DownloadManagerImpl {
// TODO: Is this ensure valid?
// The existing code was already dereferencing, so it shouldn't
// affect behaviour.
- const fileURLs = ensure(
- await this.fileObjectURLPromises.get(file.id),
- );
+ const fileURLs = (await this.fileObjectURLPromises.get(file.id))!;
if (fileURLs.isOriginal) {
const fileStream = (await fetch(fileURLs.url as string)).body;
return fileStream;
@@ -515,8 +511,8 @@ async function getRenderableFileURL(
}
}
- // TODO: Can we remove this ensure and reflect it in the types?
- return { url: ensure(url), isOriginal, isRenderable, type, mimeType };
+ // TODO: Can we remove this non-null assertion and reflect it in the types?
+ return { url: url!, isOriginal, isRenderable, type, mimeType };
}
async function getRenderableLivePhotoURL(
diff --git a/web/packages/new/photos/services/ml/blob.ts b/web/packages/new/photos/services/ml/blob.ts
index 234a030172..380c7bfa0d 100644
--- a/web/packages/new/photos/services/ml/blob.ts
+++ b/web/packages/new/photos/services/ml/blob.ts
@@ -3,7 +3,6 @@ import type { ElectronMLWorker } from "@/base/types/ipc";
import type { EnteFile } from "@/media/file";
import { FileType } from "@/media/file-type";
import { decodeLivePhoto } from "@/media/live-photo";
-import { ensure } from "@/utils/ensure";
import { renderableImageBlob } from "../../utils/file";
import { readStream } from "../../utils/native-stream";
import DownloadManager from "../download";
@@ -44,7 +43,7 @@ export const createImageBitmapAndData = async (
// Use an OffscreenCanvas to get the bitmap's data.
const offscreenCanvas = new OffscreenCanvas(width, height);
- const ctx = ensure(offscreenCanvas.getContext("2d"));
+ const ctx = offscreenCanvas.getContext("2d")!;
ctx.drawImage(imageBitmap, 0, 0, width, height);
const imageData = ctx.getImageData(0, 0, width, height);
@@ -93,7 +92,7 @@ const fetchRenderableUploadItemBlob = async (
const fileType = file.metadata.fileType;
if (fileType == FileType.video) {
const thumbnailData = await DownloadManager.getThumbnail(file);
- return new Blob([ensure(thumbnailData)]);
+ return new Blob([thumbnailData!]);
} else {
const blob = await readNonVideoUploadItem(uploadItem, electron);
return renderableImageBlob(file.metadata.title, blob);
@@ -148,7 +147,7 @@ export const fetchRenderableEnteFileBlob = async (
const fileType = file.metadata.fileType;
if (fileType == FileType.video) {
const thumbnailData = await DownloadManager.getThumbnail(file);
- return new Blob([ensure(thumbnailData)]);
+ return new Blob([thumbnailData!]);
}
const fileStream = await DownloadManager.getFile(file);
diff --git a/web/packages/new/photos/services/user-details.ts b/web/packages/new/photos/services/user-details.ts
index f3d9dfc13f..29716d1b03 100644
--- a/web/packages/new/photos/services/user-details.ts
+++ b/web/packages/new/photos/services/user-details.ts
@@ -1,7 +1,6 @@
import { authenticatedRequestHeaders, ensureOk } from "@/base/http";
import { getKV, setKV } from "@/base/kv";
import { apiURL, familyAppOrigin, paymentsAppOrigin } from "@/base/origins";
-import { ensure } from "@/utils/ensure";
import {
nullishToEmpty,
nullishToZero,
@@ -336,7 +335,7 @@ export const verifyStripeSubscription = async (
}),
);
await syncUserDetails();
- return ensure(userDetailsSnapshot()?.subscription);
+ return userDetailsSnapshot()!.subscription;
};
/**