2024-08-05 00:23:17 +00:00
|
|
|
const releaseID = document.getElementById("release").dataset.id;
|
2024-08-31 14:25:44 +00:00
|
|
|
const titleInput = document.getElementById("title");
|
|
|
|
const artworkImg = document.getElementById("artwork");
|
2024-09-01 23:15:23 +00:00
|
|
|
const removeArtworkBtn = document.getElementById("remove-artwork");
|
2024-08-31 14:25:44 +00:00
|
|
|
const artworkInput = document.getElementById("artwork-file");
|
|
|
|
const typeInput = document.getElementById("type");
|
|
|
|
const descInput = document.getElementById("description");
|
|
|
|
const dateInput = document.getElementById("release-date");
|
|
|
|
const buynameInput = document.getElementById("buyname");
|
|
|
|
const buylinkInput = document.getElementById("buylink");
|
2024-09-01 23:15:23 +00:00
|
|
|
const copyrightInput = document.getElementById("copyright");
|
|
|
|
const copyrightURLInput = document.getElementById("copyright-url");
|
2024-08-31 14:25:44 +00:00
|
|
|
const visInput = document.getElementById("visibility");
|
|
|
|
const saveBtn = document.getElementById("save");
|
|
|
|
const deleteBtn = document.getElementById("delete");
|
|
|
|
|
|
|
|
var artworkData = artworkImg.attributes.src.value;
|
2024-08-05 00:23:17 +00:00
|
|
|
|
2024-09-01 23:15:23 +00:00
|
|
|
saveBtn.addEventListener("click", () => {
|
2024-08-31 14:25:44 +00:00
|
|
|
fetch("/api/v1/music/" + releaseID, {
|
|
|
|
method: "PUT",
|
2024-09-01 23:15:23 +00:00
|
|
|
body: JSON.stringify({
|
|
|
|
visible: visInput.value === "true",
|
|
|
|
title: titleInput.value,
|
|
|
|
description: descInput.value,
|
|
|
|
type: typeInput.value,
|
|
|
|
releaseDate: dateInput.value + ":00Z",
|
|
|
|
artwork: artworkData,
|
|
|
|
buyname: buynameInput.value,
|
|
|
|
buylink: buylinkInput.value,
|
|
|
|
copyright: copyrightInput.value,
|
|
|
|
copyrightURL: copyrightURLInput.value,
|
|
|
|
}),
|
2024-08-31 14:25:44 +00:00
|
|
|
headers: { "Content-Type": "application/json" }
|
|
|
|
}).then(res => {
|
2024-08-05 00:23:17 +00:00
|
|
|
if (!res.ok) {
|
2024-08-31 14:25:44 +00:00
|
|
|
res.text().then(error => {
|
|
|
|
console.error(error);
|
|
|
|
alert("Failed to update release: " + error);
|
|
|
|
});
|
2024-08-05 00:23:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
location = location;
|
2024-08-31 14:25:44 +00:00
|
|
|
});
|
2024-09-01 23:15:23 +00:00
|
|
|
});
|
2024-08-31 14:25:44 +00:00
|
|
|
|
2024-09-01 23:15:23 +00:00
|
|
|
deleteBtn.addEventListener("click", () => {
|
|
|
|
if (releaseID != prompt(
|
|
|
|
"You are about to permanently delete " + releaseID + ". " +
|
|
|
|
"This action is irreversible. " +
|
|
|
|
"Please enter \"" + releaseID + "\" to continue.")) return;
|
2024-08-31 14:25:44 +00:00
|
|
|
fetch("/api/v1/music/" + releaseID, {
|
|
|
|
method: "DELETE",
|
|
|
|
}).then(res => {
|
|
|
|
if (!res.ok) {
|
|
|
|
res.text().then(error => {
|
|
|
|
console.error(error);
|
|
|
|
alert("Failed to delete release: " + error);
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
location = "/admin";
|
|
|
|
});
|
2024-09-01 23:15:23 +00:00
|
|
|
});
|
2024-08-05 00:23:17 +00:00
|
|
|
|
2024-09-01 23:15:23 +00:00
|
|
|
[titleInput, typeInput, descInput, dateInput, buynameInput, buylinkInput, copyrightInput, copyrightURLInput, visInput].forEach(input => {
|
|
|
|
input.addEventListener("change", () => {
|
|
|
|
saveBtn.disabled = false;
|
|
|
|
});
|
|
|
|
input.addEventListener("keypress", () => {
|
|
|
|
saveBtn.disabled = false;
|
|
|
|
});
|
2024-08-05 00:23:17 +00:00
|
|
|
});
|
2024-09-01 23:15:23 +00:00
|
|
|
|
2024-08-31 14:25:44 +00:00
|
|
|
artworkImg.addEventListener("click", () => {
|
|
|
|
artworkInput.addEventListener("change", () => {
|
|
|
|
if (artworkInput.files.length > 0) {
|
2024-08-31 00:30:30 +00:00
|
|
|
const reader = new FileReader();
|
|
|
|
reader.onload = e => {
|
|
|
|
const data = e.target.result;
|
2024-08-31 14:25:44 +00:00
|
|
|
artworkImg.src = data;
|
|
|
|
artworkData = data;
|
2024-09-01 23:15:23 +00:00
|
|
|
saveBtn.disabled = false;
|
2024-08-31 00:30:30 +00:00
|
|
|
};
|
2024-08-31 14:25:44 +00:00
|
|
|
reader.readAsDataURL(artworkInput.files[0]);
|
2024-08-31 00:30:30 +00:00
|
|
|
}
|
|
|
|
});
|
2024-08-31 14:25:44 +00:00
|
|
|
artworkInput.click();
|
2024-08-31 00:30:30 +00:00
|
|
|
});
|
2024-08-05 00:23:17 +00:00
|
|
|
|
|
|
|
|
2024-09-01 23:15:23 +00:00
|
|
|
removeArtworkBtn.addEventListener("click", () => {
|
|
|
|
artworkImg.src = "/img/default-cover-art.png"
|
|
|
|
artworkData = "";
|
|
|
|
saveBtn.disabled = false;
|
2024-08-31 14:25:44 +00:00
|
|
|
});
|