forked from dachan/dach
1
0
Fork 0

Implemented board options

This commit is contained in:
leca 2023-11-04 11:37:10 +03:00
parent bf994540a1
commit ad5fc689f9
1 changed files with 24 additions and 6 deletions

View File

@ -5,15 +5,16 @@ const dotenv = require('dotenv');
const MemoryStore = require('memorystore')(session); const MemoryStore = require('memorystore')(session);
const fs = require('fs'); const fs = require('fs');
const bcrypt = require('bcryptjs'); const bcrypt = require('bcryptjs');
const fileupload = require('express-fileupload'); // const fileupload = require('express-fileupload');
const app = express(); const app = express();
dotenv.config({ path: './web.env' }); dotenv.config({ path: './web.env' });
const default_board_settings = require('../default_board_settings.json');
const db = new Client({ const db = new Client({
user: process.env.DB_USER, user: process.env.DB_USER,
host: "db", host: process.env.DB_HOST,
database: process.env.DB_NAME, database: process.env.DB_NAME,
password: process.env.DB_PASS, password: process.env.DB_PASS,
port: 5432 port: 5432
@ -75,7 +76,20 @@ app.post('/api/post', async (req, res) => {
}); });
app.post('/api/createThread', async (req, res) => { app.post('/api/createThread', async (req, res) => {
const { threadName, isLocked, isPinned } = req.body; let login, token
const { boardId, threadName, isLocked, isPinned, content, options} = req.body;
try {
let currentSession = req.session;
token = currentSession.token;
login = currentSession.login;
} catch (err) {
console.log(err);
}
if (token != tokens[login]) return res.status(403).send("Невалидный токен");
// if ()
}); });
app.get('/api/getBoards', async (req, res) => { app.get('/api/getBoards', async (req, res) => {
@ -109,8 +123,9 @@ app.post('/api/login', async (req, res) => {
}); });
app.post('/api/createBoard', async (req, res) => { app.post('/api/createBoard', async (req, res) => {
const { boardId, boardTitle } = req.body;
let login, token; let login, token;
let { boardId, boardTitle, options} = req.body;
try { try {
let currentSession = req.session; let currentSession = req.session;
token = currentSession.token; token = currentSession.token;
@ -119,7 +134,8 @@ app.post('/api/createBoard', async (req, res) => {
console.log(err); console.log(err);
} }
// if (token != tokens[login] || !token) return res.status(403).send("Невалидный токен"); if (token != tokens[login] || !token) return res.status(403).send("Невалидный токен");
if (!boardId || !boardTitle) return res.status(400).send("Неверно сформирован запрос");
console.log(`Admin ${login} is creating new board: ${boardId}, ${boardTitle}`); console.log(`Admin ${login} is creating new board: ${boardId}, ${boardTitle}`);
@ -128,7 +144,9 @@ app.post('/api/createBoard', async (req, res) => {
if (boardTitle.length == 0 || boardTitle.length > 32) return res.status(401).send("Неверный размер имени борды"); if (boardTitle.length == 0 || boardTitle.length > 32) return res.status(401).send("Неверный размер имени борды");
if (queryRes.rowCount > 0) return res.status(401).send("Такая борда уже существует."); if (queryRes.rowCount > 0) return res.status(401).send("Такая борда уже существует.");
await db.query('INSERT INTO boards (board_id, board_name) VALUES ($1, $2)', [boardId, boardTitle]); if (!options) options = default_board_settings;
await db.query('INSERT INTO boards (board_id, board_name, options) VALUES ($1, $2, $3)', [boardId, boardTitle, options]);
return res.status(200).send("Борда успешно создана"); return res.status(200).send("Борда успешно создана");
}); });