upload is no longer "upload"

This commit is contained in:
oat 2020-09-02 17:37:36 +03:00
parent 721497d02e
commit 003a598307
Signed by untrusted user who does not match committer: oat
GPG key ID: DD83A9617A252385
2 changed files with 30 additions and 6 deletions

16
src/html/upload.html Normal file
View file

@ -0,0 +1,16 @@
<html>
<head>
<title>file upload</title>
</head>
<body>
<form action="/upload" method="post">
<label for="title">Title: </label><br>
<input type="text" id="title" name="title"><br>
<label for="artist">Artist: </label><br>
<input type="text" id="artist" name="artist"><br>
<label for="credit">Credit: </label><br>
<input type="text" id="credit" name="credit"><br>
<input type="submit" value="upload">
</form>
</body>
</html>

View file

@ -37,6 +37,15 @@ const logger = winston.createLogger({
]
});
function returnStatic(page) {
return (req, res) => {
fs.readFile(`src/html/${page}`, 'utf8', (err, data) => {
if (err) throw err;
res.send(data);
});
};
}
logger.info('connecting to mongodb database');
db.then(() => {
logger.info('connected to database!');
@ -49,14 +58,13 @@ db.then(() => {
app.set('config', config);
app.set('logger', logger);
app.get('/upload', async (req, res) => { // only for testing, very abusable
const file = new File({
title: 'penis', // look how mature i am
artist: 'cock'
});
app.get('/upload', returnStatic('upload.html'));
app.post('/upload', async (req, res) => { // only for testing, very abusable
const file = new File(req.body);
await file.save();
res.send('made and saved a sample file');
res.send('uploaded file');
});
app.get('/list', async (req, res) => { // only for testing