file uploading, now with the actual file
This commit is contained in:
parent
1ed6dc6185
commit
73d5962c5c
5 changed files with 21 additions and 17 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -3,4 +3,5 @@ node_modules
|
||||||
built
|
built
|
||||||
config/config.json
|
config/config.json
|
||||||
*.log
|
*.log
|
||||||
.env
|
.env
|
||||||
|
storage/files/*
|
|
@ -18,7 +18,7 @@
|
||||||
const el = document.getElementById('doc-list');
|
const el = document.getElementById('doc-list');
|
||||||
for (const doc of data) {
|
for (const doc of data) {
|
||||||
let p = document.createElement('p');
|
let p = document.createElement('p');
|
||||||
p.innerText = `${doc.artist} - ${doc.title} by ${doc.credit}`;
|
p.innerHTML = `${doc.artist} - ${doc.title} by ${doc.credit} <a href="files/${doc.id}.zip">download</a>`;
|
||||||
el.insertAdjacentElement('beforeend', p);
|
el.insertAdjacentElement('beforeend', p);
|
||||||
|
|
||||||
let charts = document.createElement('ul');
|
let charts = document.createElement('ul');
|
||||||
|
|
|
@ -54,6 +54,7 @@ db.then(() => {
|
||||||
app.use(express.urlencoded({extended: true}));
|
app.use(express.urlencoded({extended: true}));
|
||||||
app.use(fileUpload({limits: { fileSize: 50 * 1024 * 1024 }}));
|
app.use(fileUpload({limits: { fileSize: 50 * 1024 * 1024 }}));
|
||||||
app.use(express.static('public', {extensions: ['html', 'htm']}));
|
app.use(express.static('public', {extensions: ['html', 'htm']}));
|
||||||
|
app.use(express.static('storage', {extensions: ['zip']}));
|
||||||
app.use('/assets', express.static('assets'));
|
app.use('/assets', express.static('assets'));
|
||||||
|
|
||||||
app.set('db', db);
|
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
|
storeEntries: true
|
||||||
});
|
});
|
||||||
|
|
||||||
zip.on('ready', () => {
|
zip.on('ready', async () => {
|
||||||
const smFile = Object.values(zip.entries()).find((f: any) =>
|
const smFile = Object.values(zip.entries()).find((f: any) =>
|
||||||
!f.isDirectory && (f.name.endsWith('.sm'))
|
!f.isDirectory && (f.name.endsWith('.sm'))
|
||||||
);
|
);
|
||||||
|
@ -36,11 +36,23 @@ export function run(app) {
|
||||||
|
|
||||||
logger.info(`${chart.artist} - ${chart.title} was just uploaded`);
|
logger.info(`${chart.artist} - ${chart.title} was just uploaded`);
|
||||||
|
|
||||||
const file = new File(chart);
|
let id = 0;
|
||||||
file.save();
|
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
|
chart.createdAt = new Date();
|
||||||
res.send(chart);
|
|
||||||
|
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();
|
zip.close();
|
||||||
|
|
Loading…
Reference in a new issue