Token upload
This commit is contained in:
+36
-1
@@ -348,7 +348,12 @@ function renderCards(slug, cards) {
|
||||
addSection = document.createElement("div");
|
||||
addSection.className = "edit-add-section";
|
||||
addSection.innerHTML = `
|
||||
<div class="section-label">Search to Add</div>
|
||||
<div class="section-label">Upload Image (token / custom card)</div>
|
||||
<input id="uploadName" placeholder="Card name..." autocomplete="off" />
|
||||
<input id="uploadFile" type="file" accept="image/*" />
|
||||
<div class="row"><button class="btn btn-blue" onclick="uploadImage()" style="margin-top:4px">Upload</button></div>
|
||||
<div id="uploadError" class="error-text" style="display:none"></div>
|
||||
<div class="section-label" style="margin-top:12px">Search to Add</div>
|
||||
<div class="search-box">
|
||||
<input id="searchInput" placeholder="Card name..." oninput="onSearchInput(this.value)" autocomplete="off" />
|
||||
<div class="search-results" id="searchResults"></div>
|
||||
@@ -421,6 +426,36 @@ async function saveEdit() {
|
||||
}
|
||||
}
|
||||
|
||||
async function uploadImage() {
|
||||
if (!activeDeck) return;
|
||||
const nameInp = document.getElementById("uploadName");
|
||||
const fileInp = document.getElementById("uploadFile");
|
||||
const errEl = document.getElementById("uploadError");
|
||||
errEl.style.display = "none";
|
||||
const name = nameInp.value.trim();
|
||||
const file = fileInp.files[0];
|
||||
if (!name || !file) {
|
||||
errEl.textContent = "Name and file required.";
|
||||
errEl.style.display = "block";
|
||||
return;
|
||||
}
|
||||
const fd = new FormData();
|
||||
fd.append("name", name);
|
||||
fd.append("file", file);
|
||||
try {
|
||||
const res = await fetch(`/decks/${activeDeck}/upload-image`, { method: "POST", body: fd });
|
||||
if (!res.ok) throw new Error(await res.text().catch(() => res.statusText));
|
||||
nameInp.value = "";
|
||||
fileInp.value = "";
|
||||
await loadDecks();
|
||||
await selectDeck(activeDeck);
|
||||
enterEditMode();
|
||||
} catch (e) {
|
||||
errEl.textContent = e.message;
|
||||
errEl.style.display = "block";
|
||||
}
|
||||
}
|
||||
|
||||
function onSearchInput(val) {
|
||||
clearTimeout(searchTimer);
|
||||
const res = document.getElementById("searchResults");
|
||||
|
||||
Reference in New Issue
Block a user