From 1986f71757f2132838c4aa68b7575e4ea94ceb3b Mon Sep 17 00:00:00 2001 From: "Jill \"oatmealine\" Monoids" Date: Fri, 4 Mar 2022 18:25:25 +0300 Subject: [PATCH] fixes n stuff i am aware this is the worst commit message ever. leave me alone this is a personal project --- index.js | 12 +++++++++--- package-lock.json | 1 + package.json | 1 + 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index a708497..bb0f33f 100644 --- a/index.js +++ b/index.js @@ -2,6 +2,7 @@ require('dotenv').config(); const postgres = require('postgres'); const express = require('express'); +const bodyParser = require('body-parser'); const app = express(); const Hashids = require('hashids'); const expressws = require('express-ws'); @@ -16,6 +17,8 @@ const storage = multer.diskStorage({ } }); +const jsonParser = bodyParser.json(); + const upload = multer({ storage: storage, fileFilter: (req, file, cb) => { if (!imageFormats.includes(file.mimetype)) return cb(null, false); cb(null, true); @@ -36,9 +39,12 @@ app.use((req, res, next) => { next(); }); -app.post('/create', async (req, res) => { - const [id] = await sql`SELECT id FROM charts ORDER BY id DESC LIMIT 1`; - let newid = (id || 0) + 1; +app.post('/create', jsonParser, async (req, res) => { + const [r] = await sql`SELECT id FROM charts ORDER BY id DESC LIMIT 1`; + let newid = 1; + if (r) newid = r.id + 1; + + console.log(req.body); let body = req.body || {}; await sql` diff --git a/package-lock.json b/package-lock.json index 67c46bb..c131e0b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "1.0.0", "license": "AGPL-3.0-or-later", "dependencies": { + "body-parser": "^1.19.2", "dotenv": "^16.0.0", "express": "^4.17.3", "express-ws": "^5.0.2", diff --git a/package.json b/package.json index 275a7ae..b76f0bd 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "author": "oatmealine", "license": "AGPL-3.0-or-later", "dependencies": { + "body-parser": "^1.19.2", "dotenv": "^16.0.0", "express": "^4.17.3", "express-ws": "^5.0.2",