Fix embedding sync blocked (#1451)
This commit is contained in:
commit
814c1ebaf9
|
@ -14,6 +14,8 @@ import HTTPService from '@ente/shared/network/HTTPService';
|
|||
import { getToken } from '@ente/shared/storage/localStorage/helpers';
|
||||
import { getLatestVersionEmbeddings } from 'utils/embedding';
|
||||
import { getLocalTrashedFiles } from './trashService';
|
||||
import { getLocalCollections } from './collectionService';
|
||||
import { CustomError } from '@ente/shared/error';
|
||||
|
||||
const ENDPOINT = getEndpoint();
|
||||
|
||||
|
@ -42,6 +44,7 @@ export const syncEmbeddings = async () => {
|
|||
try {
|
||||
let embeddings = await getLocalEmbeddings();
|
||||
const localFiles = await getAllLocalFiles();
|
||||
const hiddenAlbums = await getLocalCollections('hidden');
|
||||
const localTrashFiles = await getLocalTrashedFiles();
|
||||
const fileIdToKeyMap = new Map<number, string>();
|
||||
[...localFiles, ...localTrashFiles].forEach((file) => {
|
||||
|
@ -67,7 +70,7 @@ export const syncEmbeddings = async () => {
|
|||
const worker = await ComlinkCryptoWorker.getInstance();
|
||||
const fileKey = fileIdToKeyMap.get(embedding.fileID);
|
||||
if (!fileKey) {
|
||||
throw Error('File key not found');
|
||||
throw Error(CustomError.FILE_NOT_FOUND);
|
||||
}
|
||||
const decryptedData = await worker.decryptEmbedding(
|
||||
encryptedEmbedding,
|
||||
|
@ -80,7 +83,14 @@ export const syncEmbeddings = async () => {
|
|||
embedding: decryptedData,
|
||||
} as Embedding;
|
||||
} catch (e) {
|
||||
logError(e, 'decryptEmbedding failed for file');
|
||||
let info: Record<string, unknown>;
|
||||
if (e.message === CustomError.FILE_NOT_FOUND) {
|
||||
const hasHiddenAlbums = hiddenAlbums?.length > 0;
|
||||
info = {
|
||||
hasHiddenAlbums,
|
||||
};
|
||||
}
|
||||
logError(e, 'decryptEmbedding failed for file', info);
|
||||
}
|
||||
})
|
||||
);
|
||||
|
|
|
@ -3,6 +3,9 @@ import { Embedding } from 'types/embedding';
|
|||
export const getLatestVersionEmbeddings = (embeddings: Embedding[]) => {
|
||||
const latestVersionEntities = new Map<number, Embedding>();
|
||||
embeddings.forEach((embedding) => {
|
||||
if (!embedding?.fileID) {
|
||||
return;
|
||||
}
|
||||
const existingEmbeddings = latestVersionEntities.get(embedding.fileID);
|
||||
if (
|
||||
!existingEmbeddings ||
|
||||
|
|
|
@ -84,6 +84,7 @@ export const CustomError = {
|
|||
TWO_FACTOR_ENABLED: 'two factor enabled',
|
||||
CLIENT_ERROR: 'client error',
|
||||
ServerError: 'server error',
|
||||
FILE_NOT_FOUND: 'file not found',
|
||||
};
|
||||
|
||||
export function handleUploadError(error: any): Error {
|
||||
|
|
Loading…
Reference in a new issue