From eb263ce7a4f0a560e22baf4d0801f2bdf5c18150 Mon Sep 17 00:00:00 2001 From: Benjamin Admin Date: Fri, 20 Mar 2026 12:42:53 +0100 Subject: [PATCH] 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 --- pitch-deck/lib/hooks/usePresenterMode.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/pitch-deck/lib/hooks/usePresenterMode.ts b/pitch-deck/lib/hooks/usePresenterMode.ts index a517115..cd157fc 100644 --- a/pitch-deck/lib/hooks/usePresenterMode.ts +++ b/pitch-deck/lib/hooks/usePresenterMode.ts @@ -31,14 +31,17 @@ interface UsePresenterModeReturn { setTtsEnabled: (enabled: boolean) => void } -// Client-side audio cache: text hash → blob URL +// Client-side audio cache: text key → blob URL const audioCache = new Map() -async function hashText(text: string): Promise { - const encoder = new TextEncoder() - const data = encoder.encode(text) - const hash = await crypto.subtle.digest('SHA-256', data) - return Array.from(new Uint8Array(hash)).slice(0, 8).map(b => b.toString(16).padStart(2, '0')).join('') +function cacheKey(text: string, lang: string): string { + // Simple string hash — no crypto.subtle needed (works on HTTP too) + let hash = 0 + const str = text + '|' + lang + 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({ @@ -162,7 +165,7 @@ export function usePresenterMode({ const playAudio = async () => { try { - const key = await hashText(text + language) + const key = cacheKey(text, language) let blobUrl = audioCache.get(key) if (!blobUrl) {