Add audiowidget endpoint: Blueprint renders audiowidget.tmpl, PaneCP fetches it on synthesis completion

This commit is contained in:
c0dev0id
2026-06-24 18:52:26 +02:00
parent 06c077b7f8
commit be338c2de0
5 changed files with 60 additions and 16 deletions

View File

@@ -44,3 +44,12 @@ export async function fetchStatus(credentials) {
if (!res.ok) throw new Error(`${res.status} ${res.statusText}`);
return res.json();
}
export async function fetchAudioWidget(resultUrl, errors) {
const params = new URLSearchParams();
if (resultUrl) params.set('result_url', resultUrl);
if (errors) params.set('errors', errors);
const res = await fetch(`${U.audiowidget}?${params}`);
if (!res.ok || res.status === 204) return '';
return res.text();
}

View File

@@ -1,5 +1,5 @@
import { h, ref } from 'vue';
import { fetchScoreText, putScoreText, URLS } from '../api.js';
import { h, ref, watch } from 'vue';
import { fetchScoreText, putScoreText, fetchAudioWidget, URLS } from '../api.js';
import { patchScore } from '../exporter.js';
import { StatusPoller } from './StatusPoller.js';
@@ -40,6 +40,18 @@ export const PaneCP = {
setup(props) {
const exporting = ref(false);
const exportError = ref('');
const audioWidgetHtml = ref('');
watch(
() => props.store.synthesisStatus,
async (s) => {
if (!s?.frozen) { audioWidgetHtml.value = ''; return; }
audioWidgetHtml.value = await fetchAudioWidget(
s.file_accomplished ? URLS.result : null,
s.errors ?? null,
);
},
);
async function doExport() {
exportError.value = '';
@@ -118,18 +130,10 @@ export const PaneCP = {
store.synthesisStatus && !store.synthesisStatus.frozen
? h(StatusPoller, { store }) : null,
// Synthesis error
store.synthesisStatus?.frozen && store.synthesisStatus?.errors
? h('div', { class: 'se-error', style: 'margin-top:0.5rem' },
store.synthesisStatus.errors) : null,
// Audio result
store.synthesisStatus?.file_accomplished
? h('audio', {
controls: true,
src: URLS.result,
style: 'display:block;width:100%;margin-top:0.5rem',
}) : null,
// Audio widget (rendered server-side from audiowidget.tmpl)
audioWidgetHtml.value
? h('div', { innerHTML: audioWidgetHtml.value, style: 'margin-top:0.5rem' })
: null,
]);
};
},