From 58ed869b3d29115b38d4439bd8ed8d29e6eca5bf Mon Sep 17 00:00:00 2001 From: ItzCrazyKns <95534749+ItzCrazyKns@users.noreply.github.com> Date: Thu, 26 Mar 2026 22:19:48 +0530 Subject: [PATCH] feat(utils): move hash into utils --- src/lib/config/index.ts | 2 +- src/lib/uploads/store.ts | 3 +-- src/lib/utils/hash.ts | 7 +++++++ 3 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 src/lib/utils/hash.ts diff --git a/src/lib/config/index.ts b/src/lib/config/index.ts index 48305381..38e12eb1 100644 --- a/src/lib/config/index.ts +++ b/src/lib/config/index.ts @@ -1,7 +1,7 @@ import path from 'node:path'; import fs from 'fs'; import { Config, ConfigModelProvider, UIConfigSections } from './types'; -import { hashObj } from '../serverUtils'; +import { hashObj } from '../utils/hash'; import { getModelProvidersUIConfigSection } from '../models/providers'; class ConfigManager { diff --git a/src/lib/uploads/store.ts b/src/lib/uploads/store.ts index 29afeb02..711ff523 100644 --- a/src/lib/uploads/store.ts +++ b/src/lib/uploads/store.ts @@ -2,8 +2,7 @@ import BaseEmbedding from "../models/base/embedding"; import UploadManager from "./manager"; import computeSimilarity from "../utils/computeSimilarity"; import { Chunk } from "../types"; -import { hashObj } from "../serverUtils"; -import fs from 'fs'; +import { hashObj } from '../utils/hash'; type UploadStoreParams = { embeddingModel: BaseEmbedding; diff --git a/src/lib/utils/hash.ts b/src/lib/utils/hash.ts new file mode 100644 index 00000000..9dca22f8 --- /dev/null +++ b/src/lib/utils/hash.ts @@ -0,0 +1,7 @@ +import crypto from 'crypto'; + +export const hashObj = (obj: { [key: string]: any }) => { + const json = JSON.stringify(obj, Object.keys(obj).sort()); + const hash = crypto.createHash('sha256').update(json).digest('hex'); + return hash; +};