Compare commits
2 commits
1ed6dc6185
...
6b07ef943d
Author | SHA1 | Date | |
---|---|---|---|
|
6b07ef943d | ||
|
73d5962c5c |
7 changed files with 58 additions and 54 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -3,4 +3,5 @@ node_modules
|
|||
built
|
||||
config/config.json
|
||||
*.log
|
||||
.env
|
||||
.env
|
||||
storage/files/*
|
|
@ -1,14 +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>
|
||||
<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>
|
||||
<body>
|
||||
<h1>Hi</h1>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -1,37 +1,37 @@
|
|||
<!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>
|
||||
<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>
|
||||
<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);
|
||||
<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.innerHTML = `${doc.artist} - ${doc.title} by ${doc.credit} <a href="files/${doc.id}.zip">download</a>`;
|
||||
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}\n` +
|
||||
`${chart.steps} steps, ${chart.mines} mines, ${chart.jumps} jumps, ${chart.hands} hands, ${chart.holds} holds, ${chart.rolls} rolls`
|
||||
charts.insertAdjacentElement('beforeend', l);
|
||||
}
|
||||
el.insertAdjacentElement('beforeend', charts);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
let charts = document.createElement('ul');
|
||||
for (const chart of doc.charts) {
|
||||
let l = document.createElement('li');
|
||||
l.innerText = `${chart.difficulty} ${chart.rating} - ${chart.name}\n` +
|
||||
`${chart.steps} steps, ${chart.mines} mines, ${chart.jumps} jumps, ${chart.hands} hands, ${chart.holds} holds, ${chart.rolls} rolls`
|
||||
charts.insertAdjacentElement('beforeend', l);
|
||||
}
|
||||
el.insertAdjacentElement('beforeend', charts);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -19,7 +19,7 @@
|
|||
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 {
|
||||
|
|
|
@ -54,6 +54,7 @@ db.then(() => {
|
|||
app.use(express.urlencoded({extended: true}));
|
||||
app.use(fileUpload({limits: { fileSize: 50 * 1024 * 1024 }}));
|
||||
app.use(express.static('public', {extensions: ['html', 'htm']}));
|
||||
app.use(express.static('storage', {extensions: ['zip']}));
|
||||
app.use('/assets', express.static('assets'));
|
||||
|
||||
app.set('db', db);
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
import * as fs from 'fs';
|
||||
|
||||
export function returnStatic(page) {
|
||||
return (req, res) => {
|
||||
fs.readFile(`src/html/${page}`, 'utf8', (err, data) => {
|
||||
if (err) throw err;
|
||||
res.send(data);
|
||||
});
|
||||
};
|
||||
}
|
|
@ -23,7 +23,7 @@ export function run(app) {
|
|||
storeEntries: true
|
||||
});
|
||||
|
||||
zip.on('ready', () => {
|
||||
zip.on('ready', async () => {
|
||||
const smFile = Object.values(zip.entries()).find((f: any) =>
|
||||
!f.isDirectory && (f.name.endsWith('.sm'))
|
||||
);
|
||||
|
@ -36,11 +36,23 @@ export function run(app) {
|
|||
|
||||
logger.info(`${chart.artist} - ${chart.title} was just uploaded`);
|
||||
|
||||
const file = new File(chart);
|
||||
file.save();
|
||||
let id = 0;
|
||||
for (const f of await File.find({})) {
|
||||
id = Math.max(f.id, id);
|
||||
}
|
||||
chart.id = id + 1;
|
||||
|
||||
// TODO: filter out _id and __v? possibly more
|
||||
res.send(chart);
|
||||
chart.createdAt = new Date();
|
||||
|
||||
fs.writeFile('./storage/files/' + (id + 1) + '.zip', file.data, (err) => {
|
||||
if (err) throw err;
|
||||
|
||||
const file = new File(chart);
|
||||
file.save();
|
||||
|
||||
// TODO: filter out _id and __v? possibly more
|
||||
res.send(chart);
|
||||
});
|
||||
}
|
||||
|
||||
zip.close();
|
||||
|
|
Loading…
Reference in a new issue