2023-07-17 00:58:16 +00:00
|
|
|
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);
|
|
|
|
};
|
|
|
|
|
2023-07-16 16:27:22 +00:00
|
|
|
const resultContainer = document.getElementById("result-container");
|
2023-07-17 00:58:16 +00:00
|
|
|
const form = document.getElementById("schematic-form");
|
2023-07-15 22:22:48 +00:00
|
|
|
form.onsubmit = async (e) => {
|
|
|
|
e.preventDefault();
|
2023-07-16 16:34:13 +00:00
|
|
|
resultContainer.innerHTML = "<p>Uploading and extracting contents...</p>";
|
2023-07-15 22:22:48 +00:00
|
|
|
const data = new FormData(form);
|
2023-07-17 00:58:16 +00:00
|
|
|
const processingTerminal = data.get("processing-terminal");
|
2023-07-15 22:22:48 +00:00
|
|
|
try {
|
|
|
|
const response = await fetch("/extracts", {
|
|
|
|
method: "POST",
|
|
|
|
body: data
|
|
|
|
});
|
2023-07-17 00:58:16 +00:00
|
|
|
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>`;
|
|
|
|
}
|
2023-07-15 22:22:48 +00:00
|
|
|
} 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
|
|
|
}
|
2023-07-17 00:58:16 +00:00
|
|
|
};
|