home to your local SPACEGIRL 馃挮
arimelody.space
1const newReleaseBtn = document.getElementById("create-release");
2const newArtistBtn = document.getElementById("create-artist");
3const newTrackBtn = document.getElementById("create-track");
4
5newReleaseBtn.addEventListener("click", event => {
6 event.preventDefault();
7 const id = prompt("Enter an ID for this release:");
8 if (id == null || id == "") return;
9
10 fetch("/api/v1/music", {
11 method: "POST",
12 headers: { "Content-Type": "application/json" },
13 body: JSON.stringify({id})
14 }).then(res => {
15 if (res.ok) location = "/admin/releases/" + id;
16 else {
17 res.text().then(err => {
18 alert("Request failed: " + err);
19 console.error(err);
20 });
21 }
22 }).catch(err => {
23 alert("Failed to create release. Check the console for details.");
24 console.error(err);
25 });
26});
27
28newArtistBtn.addEventListener("click", event => {
29 event.preventDefault();
30 const id = prompt("Enter an ID for this artist:");
31 if (id == null || id == "") return;
32
33 fetch("/api/v1/artist", {
34 method: "POST",
35 headers: { "Content-Type": "application/json" },
36 body: JSON.stringify({id})
37 }).then(res => {
38 res.text().then(text => {
39 if (res.ok) {
40 location = "/admin/artists/" + id;
41 } else {
42 alert("Request failed: " + text);
43 console.error(text);
44 }
45 })
46 }).catch(err => {
47 alert("Failed to create artist. Check the console for details.");
48 console.error(err);
49 });
50});
51
52newTrackBtn.addEventListener("click", event => {
53 event.preventDefault();
54 const title = prompt("Enter an title for this track:");
55 if (title == null || title == "") return;
56
57 fetch("/api/v1/track", {
58 method: "POST",
59 headers: { "Content-Type": "application/json" },
60 body: JSON.stringify({title})
61 }).then(res => {
62 res.text().then(text => {
63 if (res.ok) {
64 location = "/admin/tracks/" + text;
65 } else {
66 alert("Request failed: " + text);
67 console.error(text);
68 }
69 })
70 }).catch(err => {
71 alert("Failed to create track. Check the console for details.");
72 console.error(err);
73 });
74});