Skip to content

armgit / ente

Public Imported from GitHub
0

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

add file path exists check and correct model check

Abhinav40ab33a903bb
diff --git a/src/constants/errors.ts b/src/constants/errors.ts
index 9c946d672b..e54e856ce6 100644
--- a/src/constants/errors.ts
+++ b/src/constants/errors.ts
@@ -7,4 +7,6 @@ export const CustomErrors = {
`Unsupported platform - ${platform} ${arch}`,
MODEL_DOWNLOAD_PENDING:
'Model download pending, skipping clip search request',
+ INVALID_FILE_PATH: 'Invalid file path',
+ INVALID_CLIP_MODEL: (model: string) => `Invalid Clip model - ${model}`,
};
diff --git a/src/services/clipService.ts b/src/services/clipService.ts
index ebeb3c38bc..4b9de8c2ff 100644
--- a/src/services/clipService.ts
+++ b/src/services/clipService.ts
@@ -212,10 +212,15 @@ export async function computeImageEmbedding(
model: Model,
inputFilePath: string
): Promise<Float32Array> {
+ if (!existsSync(inputFilePath)) {
+ throw Error(CustomErrors.INVALID_FILE_PATH);
+ }
if (model === Model.GGML_CLIP) {
return await computeGGMLImageEmbedding(inputFilePath);
- } else {
+ } else if (model === Model.ONNX_CLIP) {
return await computeONNXImageEmbedding(inputFilePath);
+ } else {
+ throw Error(CustomErrors.INVALID_CLIP_MODEL(model));
}
}