Skip to content

armgit / ente

Public Imported from GitHub
0

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

nn fin

Manav Rathi1efaefbf9ce5
diff --git a/desktop/src/main/services/ffmpeg.ts b/desktop/src/main/services/ffmpeg.ts
index 3252f3f445..0cc2fd04f0 100644
--- a/desktop/src/main/services/ffmpeg.ts
+++ b/desktop/src/main/services/ffmpeg.ts
@@ -1,7 +1,6 @@
import pathToFfmpeg from "ffmpeg-static";
import fs from "node:fs/promises";
import type { ZipItem } from "../../types/ipc";
-import { ensure } from "../utils/common";
import { execAsync } from "../utils/electron";
import {
deleteTempFileIgnoringErrors,
@@ -99,7 +98,7 @@ const ffmpegBinaryPath = () => {
// This substitution of app.asar by app.asar.unpacked is suggested by the
// ffmpeg-static library author themselves:
// https://github.com/eugeneware/ffmpeg-static/issues/16
- return ensure(pathToFfmpeg).replace("app.asar", "app.asar.unpacked");
+ return pathToFfmpeg!.replace("app.asar", "app.asar.unpacked");
};
/**
diff --git a/desktop/src/main/services/ml-worker.ts b/desktop/src/main/services/ml-worker.ts
index 8a756f72eb..5f465f6c8c 100644
--- a/desktop/src/main/services/ml-worker.ts
+++ b/desktop/src/main/services/ml-worker.ts
@@ -16,7 +16,7 @@ import fs from "node:fs/promises";
import path from "node:path";
import * as ort from "onnxruntime-node";
import { messagePortMainEndpoint } from "../utils/comlink";
-import { ensure, wait } from "../utils/common";
+import { wait } from "../utils/common";
import { writeStream } from "../utils/stream";
/**
@@ -68,7 +68,7 @@ process.parentPort.once("message", (e) => {
detectFaces,
computeFaceEmbeddings,
},
- messagePortMainEndpoint(ensure(e.ports[0])),
+ messagePortMainEndpoint(e.ports[0]!),
);
});
@@ -80,7 +80,7 @@ process.parentPort.once("message", (e) => {
let _userDataPath: string | undefined;
/** Equivalent to app.getPath("userData") */
-const userDataPath = () => ensure(_userDataPath);
+const userDataPath = () => _userDataPath!;
const parseInitData = (data: unknown) => {
if (
@@ -250,7 +250,7 @@ export const computeCLIPImageEmbedding = async (
const results = await session.run(feeds);
log.debugString(`ONNX/CLIP image embedding took ${Date.now() - t} ms`);
/* Need these model specific casts to type the result */
- return ensure(results.output).data as Float32Array;
+ return results.output!.data as Float32Array;
};
const cachedCLIPTextSession = makeCachedInferenceSession(
@@ -290,7 +290,7 @@ export const computeCLIPTextEmbeddingIfAvailable = async (text: string) => {
const t = Date.now();
const results = await session.run(feeds);
log.debugString(`ONNX/CLIP text embedding took ${Date.now() - t} ms`);
- return ensure(results.output).data as Float32Array;
+ return results.output!.data as Float32Array;
};
const cachedFaceDetectionSession = makeCachedInferenceSession(
@@ -311,7 +311,7 @@ export const detectFaces = async (
const t = Date.now();
const results = await session.run(feeds);
log.debugString(`ONNX/YOLO face detection took ${Date.now() - t} ms`);
- return ensure(results.output).data;
+ return results.output!.data;
};
const cachedFaceEmbeddingSession = makeCachedInferenceSession(
diff --git a/desktop/src/main/utils/common.ts b/desktop/src/main/utils/common.ts
index 929281d740..486b5570c4 100644
--- a/desktop/src/main/utils/common.ts
+++ b/desktop/src/main/utils/common.ts
@@ -5,15 +5,6 @@
* currently a common package that both of them share.
*/
-/**
- * Throw an exception if the given value is `null` or `undefined`.
- */
-export const ensure = <T>(v: T | null | undefined): T => {
- if (v === null) throw new Error("Required value was null");
- if (v === undefined) throw new Error("Required value was not found");
- return v;
-};
-
/**
* Wait for {@link ms} milliseconds
*
diff --git a/desktop/src/main/utils/temp.ts b/desktop/src/main/utils/temp.ts
index 85bfeae33e..c50fb2081f 100644
--- a/desktop/src/main/utils/temp.ts
+++ b/desktop/src/main/utils/temp.ts
@@ -5,7 +5,6 @@ import path from "node:path";
import type { ZipItem } from "../../types/ipc";
import log from "../log";
import { markClosableZip, openZip } from "../services/zip";
-import { ensure } from "./common";
/**
* Our very own directory within the system temp directory. Go crazy, but
@@ -20,7 +19,7 @@ const enteTempDirPath = async () => {
/** Generate a random string suitable for being used as a file name prefix */
const randomPrefix = () => {
const ch = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
- const randomChar = () => ensure(ch[Math.floor(Math.random() * ch.length)]);
+ const randomChar = () => ch[Math.floor(Math.random() * ch.length)]!;
return Array(10).fill("").map(randomChar).join("");
};