diff --git a/src/html/upload.html b/src/html/upload.html new file mode 100644 index 0000000..8670e9e --- /dev/null +++ b/src/html/upload.html @@ -0,0 +1,16 @@ + + + file upload + + +
+
+
+
+
+
+
+ +
+ + \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index ec12a8c..1c42f95 100644 --- a/src/index.ts +++ b/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