fixes n stuff

i am aware this is the worst commit message ever. leave me alone this is a personal project
This commit is contained in:
Jill 2022-03-04 18:25:25 +03:00
parent bafc0e1e36
commit 1986f71757
3 changed files with 11 additions and 3 deletions

View File

@ -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`

1
package-lock.json generated
View File

@ -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",

View File

@ -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",