forked from dachan/dach
1
0
Fork 0

changed /api/getPosts

This commit is contained in:
leca 2023-11-17 09:16:05 +03:00
parent d61797a748
commit 0b3a178715
1 changed files with 2 additions and 4 deletions

View File

@ -69,8 +69,8 @@ app.post('/api/uploadMedia', async (req, res) => {
app.get('/api/getPosts/:boardId/:threadId', async (req, res) => { app.get('/api/getPosts/:boardId/:threadId', async (req, res) => {
posts = []; posts = [];
(await db.query('SELECT post_id FROM posts WHERE board_id = $1 AND thread_id = $2', [req.params.boardId, req.params.threadId])).rows (await db.query('SELECT post_id, content, timestamp, options FROM posts WHERE board_id = $1 AND thread_id = $2', [req.params.boardId, req.params.threadId])).rows
.forEach((post) => posts.push(post.post_id)) .forEach((post) => posts.push(post))
res.setHeader('Content-Type', 'application/json'); res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(posts)); res.end(JSON.stringify(posts));
@ -133,12 +133,10 @@ app.post('/api/createThread', async (req, res) => {
await db.query('INSERT INTO posts (board_id, thread_id, post_id, content, is_root, timestamp, user_ip) VALUES($1, $2, $3, $4, $5, NOW(), $6)', [boardId, threadId, postId, content, true, req.socket.remoteAddress]); await db.query('INSERT INTO posts (board_id, thread_id, post_id, content, is_root, timestamp, user_ip) VALUES($1, $2, $3, $4, $5, NOW(), $6)', [boardId, threadId, postId, content, true, req.socket.remoteAddress]);
await db.query('INSERT INTO threads (board_id, thread_id, thread_name, posts_ids, is_locked, is_pinned, options) VALUES ($1, $2, $3, $4, $5, $6, $7)', [boardId, threadId, threadTitle, [postId], isLocked, isPinned, options]); await db.query('INSERT INTO threads (board_id, thread_id, thread_name, posts_ids, is_locked, is_pinned, options) VALUES ($1, $2, $3, $4, $5, $6, $7)', [boardId, threadId, threadTitle, [postId], isLocked, isPinned, options]);
// await db.query('UPDATE boards SET threads_ids = ARRAY_APPEND(threads_ids, $1) WHERE board_id = $2', [threadId, boardId]);
res.redirect(`/${boardId}/${postId}`); res.redirect(`/${boardId}/${postId}`);
}); });
app.get('/api/getThreads/:boardId', async (req, res) => { app.get('/api/getThreads/:boardId', async (req, res) => {
// let queryRes = (await db.query('SELECT * FROM boards WHERE board_id = $1', [req.params.boardId])).rows[0];
threads = []; threads = [];
(await db.query('SELECT thread_id FROM threads WHERE board_id = $1', [req.params.boardId])).rows (await db.query('SELECT thread_id FROM threads WHERE board_id = $1', [req.params.boardId])).rows
.forEach((thread) => threads.push(thread.thread_id)) .forEach((thread) => threads.push(thread.thread_id))