Fix the putEmbeddings API calls for now
This commit is contained in:
parent
e58e96091f
commit
320db9f8b7
2 changed files with 19 additions and 1 deletions
|
@ -1,4 +1,6 @@
|
|||
import { inWorker } from "@/next/env";
|
||||
import log from "@/next/log";
|
||||
import { workerBridge } from "@/next/worker/worker-bridge";
|
||||
import ComlinkCryptoWorker from "@ente/shared/crypto";
|
||||
import { CustomError } from "@ente/shared/error";
|
||||
import HTTPService from "@ente/shared/network/HTTPService";
|
||||
|
@ -262,7 +264,9 @@ export const putEmbedding = async (
|
|||
putEmbeddingReq: PutEmbeddingRequest,
|
||||
): Promise<EncryptedEmbedding> => {
|
||||
try {
|
||||
const token = getToken();
|
||||
const token = inWorker()
|
||||
? await workerBridge.getAuthToken()
|
||||
: getToken();
|
||||
if (!token) {
|
||||
log.info("putEmbedding failed: token not found");
|
||||
throw Error(CustomError.TOKEN_MISSING);
|
||||
|
|
|
@ -35,6 +35,19 @@ export class ComlinkWorker<T extends new () => InstanceType<T>> {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO(MR): Temporary method to forward auth tokens to workers
|
||||
const getAuthToken = () => {
|
||||
// LS_KEYS.USER
|
||||
const userJSONString = localStorage.getItem("user");
|
||||
if (!userJSONString) return undefined;
|
||||
const json: unknown = JSON.parse(userJSONString);
|
||||
if (!json || typeof json != "object" || !("token" in json))
|
||||
return undefined;
|
||||
const token = json.token;
|
||||
if (typeof token != "string") return undefined;
|
||||
return token;
|
||||
};
|
||||
|
||||
/**
|
||||
* A minimal set of utility functions that we expose to all workers that we
|
||||
* create.
|
||||
|
@ -44,6 +57,7 @@ export class ComlinkWorker<T extends new () => InstanceType<T>> {
|
|||
*/
|
||||
const workerBridge = {
|
||||
logToDisk,
|
||||
getAuthToken,
|
||||
convertToJPEG: (inputFileData: Uint8Array, filename: string) =>
|
||||
ensureElectron().convertToJPEG(inputFileData, filename),
|
||||
detectFaces: (input: Float32Array) => ensureElectron().detectFaces(input),
|
||||
|
|
Loading…
Reference in a new issue