From 003a5983079d1c74cb7c25b91cb18adf4dec2606 Mon Sep 17 00:00:00 2001 From: oat Date: Wed, 2 Sep 2020 17:37:36 +0300 Subject: [PATCH] upload is no longer "upload" --- src/html/upload.html | 16 ++++++++++++++++ src/index.ts | 20 ++++++++++++++------ 2 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 src/html/upload.html 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