forked from oat/in-the-database-2
slightly better (but still temporary) frontend and /api
This commit is contained in:
parent
758e2ef7e2
commit
4635778e0d
7 changed files with 100 additions and 44 deletions
14
public/index.html
Normal file
14
public/index.html
Normal file
|
@ -0,0 +1,14 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Index</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Hi</h1>
|
||||
</body>
|
||||
|
||||
</html>
|
36
public/list.html
Normal file
36
public/list.html
Normal file
|
@ -0,0 +1,36 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>list</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="doc-list">
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/axios@0.20.0/dist/axios.min.js"></script>
|
||||
<script>
|
||||
axios.get('/api/list').then(({ data }) => {
|
||||
console.log(data);
|
||||
const el = document.getElementById('doc-list');
|
||||
for (const doc of data) {
|
||||
let p = document.createElement('p');
|
||||
p.innerText = `${doc.artist} - ${doc.title} by ${doc.credit}`;
|
||||
el.insertAdjacentElement('beforeend', p);
|
||||
|
||||
let charts = document.createElement('ul');
|
||||
for (const chart of doc.charts) {
|
||||
let l = document.createElement('li');
|
||||
l.innerText = `${chart.difficulty} ${chart.rating} - ${chart.name}`
|
||||
charts.insertAdjacentElement('beforeend', l);
|
||||
}
|
||||
el.insertAdjacentElement('beforeend', charts);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
37
public/upload.html
Normal file
37
public/upload.html
Normal file
|
@ -0,0 +1,37 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>File upload</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<input type="file" id="file"><br>
|
||||
<button id="upload-btn">Upload</button>
|
||||
<br>
|
||||
<p id="status-spn"></p>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/axios@0.20.0/dist/axios.min.js"></script>
|
||||
<script>
|
||||
document.getElementById('upload-btn').addEventListener('click', async () => {
|
||||
const file = document.getElementById('file');
|
||||
if (file.files.length) {
|
||||
console.log(file.files[0]);
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('file', file.files[0]);
|
||||
try {
|
||||
let response = await axios.post('/api/upload', formData);
|
||||
const chart = response.data;
|
||||
document.getElementById('status-spn').innerHTML = `<b>${chart.artist} - ${chart.title}</b> has been uploaded!`;
|
||||
} catch (error) {
|
||||
document.getElementById('status-spn').innerText = `Error: ${error.response.data}`;
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
Loading…
Add table
Add a link
Reference in a new issue