forked from oat/in-the-database-2
upload is no longer "upload"
This commit is contained in:
parent
721497d02e
commit
003a598307
2 changed files with 30 additions and 6 deletions
16
src/html/upload.html
Normal file
16
src/html/upload.html
Normal 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>
|
20
src/index.ts
20
src/index.ts
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue