2023-07-15 22:22:48 +00:00
|
|
|
const form = document.getElementById("schematic-form");
|
2023-07-16 16:27:22 +00:00
|
|
|
const resultContainer = document.getElementById("result-container");
|
2023-07-15 22:22:48 +00:00
|
|
|
form.onsubmit = async (e) => {
|
|
|
|
e.preventDefault();
|
2023-07-16 16:27:22 +00:00
|
|
|
resultContainer.innerHTML = "";
|
2023-07-15 22:22:48 +00:00
|
|
|
console.log(e);
|
|
|
|
const data = new FormData(form);
|
|
|
|
console.log(data);
|
|
|
|
try {
|
|
|
|
const response = await fetch("/extracts", {
|
|
|
|
method: "POST",
|
|
|
|
body: data
|
|
|
|
});
|
|
|
|
const result = await response.json();
|
2023-07-16 16:27:22 +00:00
|
|
|
const extractId = result.extractId;
|
|
|
|
const url = window.location.origin + "/extracts/" + extractId;
|
|
|
|
resultContainer.innerHTML = `<p>Copy this URL, and provide it to the computer: <em>${url}</em></p>`;
|
2023-07-15 22:22:48 +00:00
|
|
|
form.reset();
|
|
|
|
} catch (error) {
|
|
|
|
console.error("Error: " + error);
|
2023-07-16 16:27:22 +00:00
|
|
|
resultContainer.innerHTML = `<p>An error occurred: ${error}</p>`;
|
2023-07-15 22:22:48 +00:00
|
|
|
}
|
|
|
|
};
|