36 lines
1.6 KiB
JavaScript
36 lines
1.6 KiB
JavaScript
const addInputButton = document.getElementById("add-input-button");
|
|
const schematicInputSectionTemplate = document.getElementById("schematic-input-section").cloneNode(true);
|
|
const schematicInputSectionContainer = document.getElementById("schematic-input-section").parentElement;
|
|
addInputButton.onclick = () => {
|
|
const newSection = schematicInputSectionTemplate.cloneNode(true);
|
|
schematicInputSectionContainer.appendChild(newSection);
|
|
};
|
|
|
|
const resultContainer = document.getElementById("result-container");
|
|
const form = document.getElementById("schematic-form");
|
|
form.onsubmit = async (e) => {
|
|
e.preventDefault();
|
|
resultContainer.innerHTML = "<p>Uploading and extracting contents...</p>";
|
|
const data = new FormData(form);
|
|
const processingTerminal = data.get("processing-terminal");
|
|
try {
|
|
const response = await fetch("/extracts", {
|
|
method: "POST",
|
|
body: data
|
|
});
|
|
if (response.status === 200) {
|
|
const result = await response.json();
|
|
const extractId = result.extractId;
|
|
const url = window.location.origin + "/extracts/" + extractId;
|
|
resultContainer.innerHTML = `<p>Copy this URL, and provide it to your computer extraction terminal: <a href="${url}">${url}</a></p>`;
|
|
form.reset();
|
|
} else {
|
|
const message = await response.text();
|
|
resultContainer.innerHTML = `<p>Submission failed: <em>${message}</em></p>`;
|
|
}
|
|
} catch (error) {
|
|
console.error("Error: " + error);
|
|
resultContainer.innerHTML = `<p>An error occurred: ${error}</p>`;
|
|
}
|
|
};
|