home to your local SPACEGIRL 馃挮 arimelody.space
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 106 lines 3.6 kB view raw
1import { hijackClickEvent } from "./admin.js"; 2 3const releaseID = document.getElementById("release").dataset.id; 4const titleInput = document.getElementById("title"); 5const artworkImg = document.getElementById("artwork"); 6const removeArtworkBtn = document.getElementById("remove-artwork"); 7const artworkInput = document.getElementById("artwork-file"); 8const typeInput = document.getElementById("type"); 9const descInput = document.getElementById("description"); 10const dateInput = document.getElementById("release-date"); 11const buynameInput = document.getElementById("buyname"); 12const buylinkInput = document.getElementById("buylink"); 13const copyrightInput = document.getElementById("copyright"); 14const copyrightURLInput = document.getElementById("copyright-url"); 15const visInput = document.getElementById("visibility"); 16const saveBtn = document.getElementById("save"); 17const deleteBtn = document.getElementById("delete"); 18 19var artworkData = artworkImg.attributes.src.value; 20 21saveBtn.addEventListener("click", () => { 22 fetch("/api/v1/music/" + releaseID, { 23 method: "PUT", 24 body: JSON.stringify({ 25 visible: visInput.value === "true", 26 title: titleInput.value, 27 description: descInput.value, 28 type: typeInput.value, 29 releaseDate: dateInput.value + ":00Z", 30 artwork: artworkData, 31 buyname: buynameInput.value, 32 buylink: buylinkInput.value, 33 copyright: copyrightInput.value, 34 copyrightURL: copyrightURLInput.value, 35 }), 36 headers: { "Content-Type": "application/json" } 37 }).then(res => { 38 if (!res.ok) { 39 res.text().then(error => { 40 console.error(error); 41 alert("Failed to update release: " + error); 42 }); 43 return; 44 } 45 46 location = location; 47 }); 48}); 49 50deleteBtn.addEventListener("click", () => { 51 if (releaseID != prompt( 52 "You are about to permanently delete " + releaseID + ". " + 53 "This action is irreversible. " + 54 "Please enter \"" + releaseID + "\" to continue.")) return; 55 fetch("/api/v1/music/" + releaseID, { 56 method: "DELETE", 57 }).then(res => { 58 if (!res.ok) { 59 res.text().then(error => { 60 console.error(error); 61 alert("Failed to delete release: " + error); 62 }); 63 return; 64 } 65 66 location = "/admin"; 67 }); 68}); 69 70[titleInput, typeInput, descInput, dateInput, buynameInput, buylinkInput, copyrightInput, copyrightURLInput, visInput].forEach(input => { 71 input.addEventListener("change", () => { 72 saveBtn.disabled = false; 73 }); 74 input.addEventListener("keypress", () => { 75 saveBtn.disabled = false; 76 }); 77}); 78 79artworkImg.addEventListener("click", () => { 80 artworkInput.addEventListener("change", () => { 81 if (artworkInput.files.length > 0) { 82 const reader = new FileReader(); 83 reader.onload = e => { 84 const data = e.target.result; 85 artworkImg.src = data; 86 artworkData = data; 87 saveBtn.disabled = false; 88 }; 89 reader.readAsDataURL(artworkInput.files[0]); 90 } 91 }); 92 artworkInput.click(); 93}); 94 95 96removeArtworkBtn.addEventListener("click", () => { 97 artworkImg.src = "/img/default-cover-art.png" 98 artworkData = ""; 99 saveBtn.disabled = false; 100}); 101 102document.addEventListener("readystatechange", () => { 103 document.querySelectorAll("#credits .credit").forEach(el => { 104 hijackClickEvent(el, el.querySelector(".artist-name a")); 105 }); 106});