This repository has been archived by the owner on Jun 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.html
329 lines (298 loc) · 13.4 KB
/
example.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<title>JukeB0X</title>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">JukeB0X</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" target="_blank" href="https://edvgui.github.io/JukeB0X">API Documentation</a>
</li>
</ul>
</div>
</nav>
<div class="container-fluid">
<div class="page-header">
<h1>JukeB0X : Small example of use.</h1>
</div>
<div class="row">
<div id="alertBox" class="col">
</div>
</div>
<div class="row">
<div class="col col-lg-4 col-md-6 col-sm-12">
<div class="card">
<div class="card-header">
1. Import a file
</div>
<div class="card-body">
<h5 class="card-title">Select a file from your computer to import.</h5>
<form id="uploadForm" enctype="multipart/form-data">
<div class="form-group">
<input id="songFile" name="songFile" type="file" accept=".mp3">
</div>
<div class="form-group">
<button type="button" onclick="upload();" class="btn btn-block btn-primary float-right">Upload</button>
</div>
</form>
</div>
<div class="card-footer">
<pre><code id="uploadFooter"></code></pre>
</div>
</div>
</div>
<div class="col col-lg-4 col-md-6 col-sm-12">
<div class="card">
<div class="card-header">
2. Import multiple files
</div>
<div class="card-body">
<h5 class="card-title">Select a file from your computer to import.</h5>
<form id="uploadFormMultiple" enctype="multipart/form-data">
<div class="form-group">
<input id="songFiles" name="songFiles" type="file" accept=".mp3" multiple>
</div>
<div class="form-group">
<button type="button" onclick="uploadMultiple();" class="btn btn-block btn-primary float-right">Upload</button>
</div>
</form>
</div>
<div class="card-footer">
<pre><code id="uploadMultipleFooter"></code></pre>
</div>
</div>
</div>
<div class="col col-lg-4 col-md-6 col-sm-12">
<div class="card">
<div class="card-header">
3. Import from a url
</div>
<div class="card-body">
<h5 class="card-title">Enter a link to a file to download.</h5>
<form id="uploadFormUrl" enctype="multipart/form-data">
<div class="form-group">
<label class="control-label" for="songUrl">Url</label>
<input id="songUrl" name="songUrl" type="text" class="form-control" placeholder="Url" value="">
</div>
<div class="form-group">
<button type="button" onclick="uploadUrl();" class="btn btn-block btn-primary float-right">Upload</button>
</div>
</form>
</div>
<div class="card-footer">
<pre><code id="uploadUrlFooter"></code></pre>
</div>
</div>
</div>
<div class="col col-lg-4 col-md-6 col-sm-12">
<div class="card">
<div class="card-header">
3. Delete some files
</div>
<div class="card-body">
<h5 class="card-title">Enter a link to a file to download.</h5>
<form id="deleteForm" enctype="multipart/form-data">
<div class="form-group">
<label class="control-label" for="filePath">Path</label>
<input id="filePath" name="filePath" type="text" class="form-control" placeholder="Path" value="">
</div>
<div class="form-group">
<button type="button" onclick="deleteResource();" class="btn btn-block btn-danger float-right">Delete</button>
</div>
</form>
</div>
<div class="card-footer">
<pre><code id="deleteFooter"></code></pre>
</div>
</div>
</div>
<div class="col col-lg-4 col-md-6 col-sm-12">
<div class="card">
<div class="card-header">
3. Explore the library
</div>
<div class="card-body">
<h5 class="card-title">Navigate across the library.</h5>
<h6 id="path"></h6>
<div class="list-group" id="navs">
<a href="#" class="list-group-item list-group-item-action" onclick="library();">library</a>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<script>
const api = "http://localhost:3001";
let ref = "";
function request(url, method, data, callback) {
const req = new XMLHttpRequest();
req.onreadystatechange = function (event) {
// XMLHttpRequest.DONE === 4
if (this.readyState === XMLHttpRequest.DONE) {
callback(JSON.parse(this.response));
}
};
req.open(method, url, true);
req.send(data);
}
function library() {
const path = document.getElementById("path");
path.innerText = "/library";
request(api + path.innerText, 'GET', null, response => {
if (response.status === "success") {
const navs = document.getElementById("navs");
navs.innerHTML = "";
const refresh = document.createElement("button");
refresh.type = "button";
refresh.className = "list-group-item list-group-item-action";
refresh.innerText = " Refresh";
refresh.addEventListener("click", () => {
library();
});
navs.appendChild(refresh);
response.data.forEach((element) => {
const a = document.createElement("a");
a.href = "#";
a.className = "list-group-item list-group-item-action";
a.addEventListener("click", () => {
navigateArtist(element);
});
a.innerText = element;
navs.appendChild(a);
})
}
});
}
function navigateArtist(artist) {
const path = document.getElementById("path");
path.innerText = "/library/" + artist;
request(api + path.innerText, 'GET', null, response => {
if (response.status === "success") {
const navs = document.getElementById("navs");
navs.innerHTML = "";
const back = document.createElement("button");
back.type = "button";
back.className = "list-group-item list-group-item-action";
back.innerText = " < Go Back";
back.addEventListener("click", () => {
library();
});
navs.appendChild(back);
response.data.forEach((element) => {
const a = document.createElement("a");
a.href = "#";
a.className = "list-group-item list-group-item-action";
a.addEventListener("click", () => {
navigateAlbum(artist, element);
});
a.innerText = element;
navs.appendChild(a);
})
}
});
}
function navigateAlbum(artist, album) {
const path = document.getElementById("path");
path.innerText = "/library/" + artist + "/" + album;
request(api + path.innerText, 'GET', null, response => {
if (response.status === "success") {
const navs = document.getElementById("navs");
navs.innerHTML = "";
const back = document.createElement("button");
back.type = "button";
back.className = "list-group-item list-group-item-action";
back.innerText = " < Go Back";
back.addEventListener("click", () => {
navigateArtist(artist);
});
navs.appendChild(back);
response.data.forEach((element) => {
const a = document.createElement("a");
a.href = api + path.innerText + "/" + element;
a.className = "list-group-item list-group-item-action";
a.innerText = element;
a.download;
navs.appendChild(a);
})
}
});
}
function upload() {
const uploadForm = document.getElementById("uploadForm");
const fd = new FormData(uploadForm);
request(api + "/upload", 'POST', fd, (response) => {
if (response.status === "success") {
ref = response.ref;
}
showAlert(response.status, response.message);
document.getElementById("uploadFooter").innerText = JSON.stringify(response.data);
});
}
function uploadMultiple() {
const uploadForm = document.getElementById("uploadFormMultiple");
const fd = new FormData(uploadForm);
request(api + "/upload/many", 'POST', fd, (response) => {
if (response.status === "success") {
ref = response.ref;
}
showAlert(response.status, response.message);
document.getElementById("uploadMultipleFooter").innerText = JSON.stringify(response.data);
});
}
function uploadUrl() {
const uploadForm = document.getElementById("uploadFormUrl");
const fd = new FormData(uploadForm);
request(api + "/import", 'POST', fd, (response) => {
if (response.status === "success") {
ref = response.ref;
}
showAlert(response.status, response.message);
document.getElementById("uploadUrlFooter").innerText = JSON.stringify(response.data);
});
}
function deleteResource() {
const path = document.getElementById("filePath").value;
request(api + path, 'DELETE', null, (response) => {
showAlert(response.status, response.message);
});
}
function showAlert(status, message) {
const alertBox = document.getElementById("alertBox");
alertBox.innerText = "";
const div = document.createElement("div");
div.className = "alert alert-admissible";
if (status === "success") {
div.className += " alert-success";
} else if (status === "error") {
div.className += " alert-danger";
}
div.innerHTML += "<a href=\"#\" class=\"close\" data-dismiss=\"alert\" aria-label=\"close\">×</a>";
div.innerHTML += "<strong>" + status.toUpperCase() + "</strong> ";
div.innerHTML += message;
alertBox.appendChild(div);
}
</script>
</body>
</html>