1 OSM.downloadBlob = function (blob, filename) {
2 const url = URL.createObjectURL(blob);
3 const a = document.createElement("a");
6 document.body.appendChild(a);
8 document.body.removeChild(a);
9 URL.revokeObjectURL(url);
12 OSM.showAlert = function (message) {
13 const modalBody = document.getElementById("osm_alert_message");
14 modalBody.textContent = message;
15 const alertModal = new bootstrap.Modal(document.getElementById("osm_alert_modal"));
19 OSM.getTurboBlobHandler = function (filename) {
20 async function handleExportSuccess({ fetchResponse }) {
22 const blob = await fetchResponse.response.blob();
23 OSM.downloadBlob(blob, filename);
25 notifyExportFailure("(blob error)");
29 async function handleExportError({ error, fetchResponse }) {
31 let detailMessage = error?.message;
33 detailMessage = await fetchResponse.responseText.then(extractTextFromHTML);
35 notifyExportFailure(detailMessage);
37 notifyExportFailure("(unknown)");
41 function extractTextFromHTML(htmlString) {
42 const parser = new DOMParser();
43 const doc = parser.parseFromString(htmlString, "text/html");
44 return doc.body ? doc.body.textContent.trim() : "(unknown)";
47 function notifyExportFailure(reason) {
48 OSM.showAlert(OSM.i18n.t("javascripts.share.export_failed", { reason }));
51 return function ({ detail }) {
53 handleExportSuccess(detail);
55 handleExportError(detail);