fix(presenter): replace crypto.subtle with simple hash for HTTP compatibility
crypto.subtle requires HTTPS context. Use simple string hash instead. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -31,14 +31,17 @@ interface UsePresenterModeReturn {
|
|||||||
setTtsEnabled: (enabled: boolean) => void
|
setTtsEnabled: (enabled: boolean) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
// Client-side audio cache: text hash → blob URL
|
// Client-side audio cache: text key → blob URL
|
||||||
const audioCache = new Map<string, string>()
|
const audioCache = new Map<string, string>()
|
||||||
|
|
||||||
async function hashText(text: string): Promise<string> {
|
function cacheKey(text: string, lang: string): string {
|
||||||
const encoder = new TextEncoder()
|
// Simple string hash — no crypto.subtle needed (works on HTTP too)
|
||||||
const data = encoder.encode(text)
|
let hash = 0
|
||||||
const hash = await crypto.subtle.digest('SHA-256', data)
|
const str = text + '|' + lang
|
||||||
return Array.from(new Uint8Array(hash)).slice(0, 8).map(b => b.toString(16).padStart(2, '0')).join('')
|
for (let i = 0; i < str.length; i++) {
|
||||||
|
hash = ((hash << 5) - hash + str.charCodeAt(i)) | 0
|
||||||
|
}
|
||||||
|
return 'tts_' + (hash >>> 0).toString(36)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function usePresenterMode({
|
export function usePresenterMode({
|
||||||
@@ -162,7 +165,7 @@ export function usePresenterMode({
|
|||||||
|
|
||||||
const playAudio = async () => {
|
const playAudio = async () => {
|
||||||
try {
|
try {
|
||||||
const key = await hashText(text + language)
|
const key = cacheKey(text, language)
|
||||||
let blobUrl = audioCache.get(key)
|
let blobUrl = audioCache.get(key)
|
||||||
|
|
||||||
if (!blobUrl) {
|
if (!blobUrl) {
|
||||||
|
|||||||
Reference in New Issue
Block a user