[web] Fix SSR build (#1396)

Fixes the following error on the nightly build

Error: Attempting to assert globalThis.electron in a non-electron
context
at r
(/home/runner/work/ente/ente/web/apps/photos/.next/server/chunks/676.js:1:25418)
        ...

    > Build error occurred
    Error: Failed to collect page data for /gallery
at
/home/runner/work/ente/ente/web/node_modules/next/dist/build/utils.js:1258:15
{
      type: 'Error'
    }
This commit is contained in:
Manav Rathi 2024-04-10 09:55:28 +05:30 committed by GitHub
commit ea18608727
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,6 +1,5 @@
import { ensureElectron } from "@/next/electron";
import log from "@/next/log";
import type { Electron } from "@/next/types/ipc";
import ComlinkCryptoWorker from "@ente/shared/crypto";
import { CustomError } from "@ente/shared/error";
import { Events, eventBus } from "@ente/shared/events";
@ -65,7 +64,6 @@ export interface CLIPIndexingStatus {
* itself, is the same across clients - web and mobile.
*/
class CLIPService {
private electron: Electron;
private embeddingExtractionInProgress: AbortController | null = null;
private reRunNeeded = false;
private indexingStatus: CLIPIndexingStatus = {
@ -80,7 +78,6 @@ class CLIPService {
private unsupportedPlatform = false;
constructor() {
this.electron = ensureElectron();
this.liveEmbeddingExtractionQueue = new PQueue({
concurrency: 1,
});
@ -193,7 +190,7 @@ class CLIPService {
getTextEmbedding = async (text: string): Promise<Float32Array> => {
try {
return electron.clipTextEmbedding(text);
return ensureElectron().clipTextEmbedding(text);
} catch (e) {
if (e?.message?.includes(CustomError.UNSUPPORTED_PLATFORM)) {
this.unsupportedPlatform = true;
@ -321,7 +318,7 @@ class CLIPService {
const file = await localFile
.arrayBuffer()
.then((buffer) => new Uint8Array(buffer));
return await electron.clipImageEmbedding(file);
return await ensureElectron().clipImageEmbedding(file);
};
private encryptAndUploadEmbedding = async (