Lumi/plugins/lumi_transcription/public/transcription.js
2026-07-22 11:01:49 +02:00

23 lines
1.2 KiB
JavaScript

(() => {
const root = document.querySelector("[data-transcription-admin]");
if (!root) return;
const button = root.querySelector("[data-create-pairing]");
const status = root.querySelector("[data-status]");
button?.addEventListener("click", async () => {
button.disabled = true;
status.textContent = "Creating a one-time pairing package…";
try {
const response = await fetch("/plugins/lumi_transcription/api/pairing-package", { method: "POST", headers: { Accept: "application/json" } });
if (!response.ok) throw new Error((await response.json()).error || "Pairing package could not be created.");
const blob = await response.blob();
const disposition = response.headers.get("content-disposition") || "";
const filename = /filename="?([^";]+)"?/i.exec(disposition)?.[1] || "lumi-companion.lumi-pairing.json";
const link = document.createElement("a");
link.href = URL.createObjectURL(blob); link.download = filename; link.click();
setTimeout(() => URL.revokeObjectURL(link.href), 1000);
status.textContent = "Pairing package created. It expires in 15 minutes and works once.";
} catch (error) { status.textContent = error.message; }
finally { button.disabled = false; }
});
})();