[web]implement in-house sha1 hash function (#18651)

* implement in-house sha1 hash function

* add comment

* add test description

Co-authored-by: Antoine Clausse <antoine.clausse@overleaf.com>

* add more tests

* dedupe test strings and remove unneeded toString calls

---------

Co-authored-by: Antoine Clausse <antoine.clausse@overleaf.com>
GitOrigin-RevId: aa3f5ab3ff412696c715521381eebf176f503197
This commit is contained in:
Liangjun Song
2024-06-05 08:03:42 +00:00
committed by Copybot
co-authored by Antoine Clausse
parent a9cc32e6ed
commit 4101f4efeb
6 changed files with 227 additions and 9 deletions
@@ -1,5 +1,5 @@
// @ts-ignore
import CryptoJSSHA1 from 'crypto-js/sha1'
import { generateSHA1Hash } from '../../../shared/utils/sha1'
import {
createContext,
useContext,
@@ -94,9 +94,9 @@ export const ReferencesProvider: FC = ({ children }) => {
const docId = doc.doc_id
const snapshot = doc._doc.snapshot
const now = Date.now()
const sha1 = CryptoJSSHA1(
const sha1 = generateSHA1Hash(
'blob ' + snapshot.length + '\x00' + snapshot
).toString()
)
const CACHE_LIFETIME = 6 * 3600 * 1000 // allow reindexing every 6 hours
const cacheEntry = existingIndexHash[docId]
const isCached =