fix(voices): rename archetype say helper to avoid global collision

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
mARTin-B78 2026-10-04 18:38:44 +02:00
parent 2a06d0a488
commit b7cfe056a3
2 changed files with 11 additions and 11 deletions

File diff suppressed because one or more lines are too long

View File

@ -17,7 +17,7 @@ const st = { gender: '', age: '', pitch: '', accent: '', language: '', category:
let favs = new Set(), booted = false, token = 0, objUrl = '';
try { favs = new Set(JSON.parse(localStorage.getItem(FAV_KEY) || '[]')); } catch (_) {}
const saveFavs = () => { try { localStorage.setItem(FAV_KEY, JSON.stringify([...favs])); } catch (_) {} };
const say = m => { $a('arch-status').textContent = m; };
const archSay = m => { $a('arch-status').textContent = m; };
const lang = () => (window.__APP_LANG__ === 'de' ? 'de' : 'en');
function buildChips() {
@ -73,7 +73,7 @@ async function load(reset) {
if (reset) { st.offset = 0; $a('arch-grid').textContent = ''; }
const q = new URLSearchParams({ offset: st.offset, limit: st.favOnly ? 100 : PAGE });
['gender', 'age', 'pitch', 'accent', 'language', 'category', 'q'].forEach(k => st[k] && q.set(k, st[k]));
say(tr('Loading…'));
archSay(tr('Loading…'));
try {
const r = await fetch('/api/archetypes?' + q);
if (!r.ok) throw new Error(r.statusText);
@ -88,30 +88,30 @@ async function load(reset) {
items.forEach(a => grid.appendChild(card(a)));
st.offset += d.items.length; st.total = d.total;
$a('arch-more').hidden = st.favOnly || st.offset >= d.total;
say(grid.children.length ? grid.children.length + ' / ' + (st.favOnly ? grid.children.length : d.total) : tr('No voices match.'));
} catch (e) { if (my === token) say(tr('Could not load the gallery.')); }
archSay(grid.children.length ? grid.children.length + ' / ' + (st.favOnly ? grid.children.length : d.total) : tr('No voices match.'));
} catch (e) { if (my === token) archSay(tr('Could not load the gallery.')); }
}
async function play(a, btn) {
btn.disabled = true; say(tr('Rendering preview…'));
btn.disabled = true; archSay(tr('Rendering preview…'));
try {
const r = await fetch('/api/archetypes/' + encodeURIComponent(a) + '/preview', { method: 'POST' });
if (!r.ok) { const e = await r.json().catch(() => ({})); throw new Error(e.detail || r.statusText); }
if (objUrl) URL.revokeObjectURL(objUrl);
objUrl = URL.createObjectURL(await r.blob());
const au = $a('arch-audio'); au.src = objUrl; await au.play().catch(() => {});
say(tr('Preview ready'));
} catch (e) { say(tr('Preview failed') + ': ' + e.message); }
archSay(tr('Preview ready'));
} catch (e) { archSay(tr('Preview failed') + ': ' + e.message); }
finally { btn.disabled = false; }
}
async function use(id, btn) {
btn.disabled = true; say(tr('Saving voice…'));
btn.disabled = true; archSay(tr('Saving voice…'));
try {
const r = await fetch('/api/archetypes/' + encodeURIComponent(id) + '/use', { method: 'POST' });
if (!r.ok) { const e = await r.json().catch(() => ({})); throw new Error(e.detail || r.statusText); }
const d = await r.json();
say(tr('Voice saved') + ': ' + d.voice_id);
archSay(tr('Voice saved') + ': ' + d.voice_id);
if (typeof toast === 'function') toast(tr('Voice saved') + ': ' + d.voice_id, 'success');
if (!btn.parentNode.querySelector('.arch-open')) {
const o = document.createElement('button'); o.type = 'button'; o.className = 'btn-secondary arch-open';
@ -119,7 +119,7 @@ async function use(id, btn) {
btn.parentNode.insertBefore(o, btn.nextSibling); o.focus();
}
if (typeof loadVoiceLibrary === 'function') loadVoiceLibrary().catch(() => {});
} catch (e) { say(tr('Save failed') + ': ' + e.message); if (typeof toast === 'function') toast(e.message, 'error'); }
} catch (e) { archSay(tr('Save failed') + ': ' + e.message); if (typeof toast === 'function') toast(e.message, 'error'); }
finally { btn.disabled = false; }
}