fix unicode handling in content hash generation for hermes introduction caching
This commit is contained in:
parent
fac46e5afa
commit
db57965ef4
1 changed files with 15 additions and 2 deletions
17
uncloseai.js
17
uncloseai.js
|
|
@ -1478,8 +1478,21 @@ function openHermesModal() {
|
|||
const pageTitle = document.title;
|
||||
const pageUrl = window.location.href;
|
||||
|
||||
// Create cache key based on page content hash
|
||||
const contentHash = btoa(pageContent.substring(0, 1000)).replace(/[^a-zA-Z0-9]/g, '').substring(0, 32);
|
||||
// Create cache key based on page content hash (handle Unicode safely)
|
||||
const contentForHash = pageContent.substring(0, 1000);
|
||||
let contentHash;
|
||||
try {
|
||||
contentHash = btoa(unescape(encodeURIComponent(contentForHash))).replace(/[^a-zA-Z0-9]/g, '').substring(0, 32);
|
||||
} catch (e) {
|
||||
// Fallback: use simple string hash if btoa fails
|
||||
let hash = 0;
|
||||
for (let i = 0; i < contentForHash.length; i++) {
|
||||
const char = contentForHash.charCodeAt(i);
|
||||
hash = ((hash << 5) - hash) + char;
|
||||
hash = hash & hash; // Convert to 32bit integer
|
||||
}
|
||||
contentHash = Math.abs(hash).toString(36).substring(0, 32);
|
||||
}
|
||||
const cacheKey = `hermes-intro-${contentHash}`;
|
||||
|
||||
// Check if we have a cached introduction for this page content
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue