mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Feedback goes to chat
This commit is contained in:
parent
bd1ebea800
commit
964ce46b5f
2 changed files with 54 additions and 50 deletions
|
@ -204,6 +204,59 @@ function setup(data: SubmoduleData): void {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
app.post('/postfeedbackfile', function (req: Request, res) {
|
||||||
|
logger.LogReq(req)
|
||||||
|
const user: User = req.session.user
|
||||||
|
|
||||||
|
utils
|
||||||
|
.uploadFile(req, uloadFiles)
|
||||||
|
.then(({ filePath }) => {
|
||||||
|
const fileName = filePath.replace(publicDir, '')
|
||||||
|
const isImage = ['png', 'jpg', 'jpeg', 'gif'].some((ext) => {
|
||||||
|
return fileName.toLowerCase().includes(ext)
|
||||||
|
})
|
||||||
|
const msgObj = {
|
||||||
|
sender: user.id,
|
||||||
|
reciever: 1,
|
||||||
|
msg: fileName,
|
||||||
|
type: isImage ? 'img' : 'file',
|
||||||
|
date: new Date().getTime(),
|
||||||
|
unread: 1,
|
||||||
|
}
|
||||||
|
dbtools.Insert(msgDB, 'msgs', msgObj)
|
||||||
|
|
||||||
|
res.json({ success: true })
|
||||||
|
io.sockets.in('1').emit('chat message', msgObj)
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
res.json({ success: false, msg: 'error during uploading' })
|
||||||
|
return
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
app.post('/postfeedback', function (req: Request<{ content: string }>, res) {
|
||||||
|
logger.LogReq(req)
|
||||||
|
const user: User = req.session.user
|
||||||
|
const { content } = req.body
|
||||||
|
if (!content || !content.trim()) {
|
||||||
|
res.json({ success: false })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const msgObj = {
|
||||||
|
sender: user.id,
|
||||||
|
reciever: 1,
|
||||||
|
msg: dbtools.sanitizeQuery(req.body.content),
|
||||||
|
type: 'text',
|
||||||
|
date: new Date().getTime(),
|
||||||
|
unread: 1,
|
||||||
|
}
|
||||||
|
dbtools.Insert(msgDB, 'msgs', msgObj)
|
||||||
|
|
||||||
|
res.json({ success: true })
|
||||||
|
io.sockets.in('1').emit('chat message', msgObj)
|
||||||
|
})
|
||||||
|
|
||||||
app.get('/hasNewMsg', (req: Request, res) => {
|
app.get('/hasNewMsg', (req: Request, res) => {
|
||||||
const user: User = req.session.user
|
const user: User = req.session.user
|
||||||
const userid: number = user.id
|
const userid: number = user.id
|
||||||
|
|
|
@ -20,63 +20,14 @@
|
||||||
|
|
||||||
import { Response } from 'express'
|
import { Response } from 'express'
|
||||||
|
|
||||||
import logger from '../../../utils/logger'
|
|
||||||
import utils from '../../../utils/utils'
|
import utils from '../../../utils/utils'
|
||||||
import { Request, SubmoduleData, User } from '../../../types/basicTypes'
|
import { Request, SubmoduleData } from '../../../types/basicTypes'
|
||||||
|
|
||||||
const msgFile = 'stats/msgs'
|
|
||||||
const uloadFiles = 'data/f'
|
const uloadFiles = 'data/f'
|
||||||
|
|
||||||
function setup(data: SubmoduleData): void {
|
function setup(data: SubmoduleData): void {
|
||||||
const { app /* userDB, url, publicdirs, moduleSpecificData */ } = data
|
const { app /* userDB, url, publicdirs, moduleSpecificData */ } = data
|
||||||
|
|
||||||
app.post('/postfeedbackfile', function (req: Request, res: Response) {
|
|
||||||
utils
|
|
||||||
.uploadFile(req, uloadFiles)
|
|
||||||
.then(() => {
|
|
||||||
res.json({ success: true })
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
res.json({ success: false, msg: 'error during uploading' })
|
|
||||||
return
|
|
||||||
})
|
|
||||||
|
|
||||||
logger.LogReq(req)
|
|
||||||
logger.Log('New feedback file', logger.GetColor('bluebg'))
|
|
||||||
})
|
|
||||||
|
|
||||||
app.post('/postfeedback', function (req: Request, res: Response) {
|
|
||||||
logger.LogReq(req)
|
|
||||||
if (req.body.fromLogin) {
|
|
||||||
logger.Log(
|
|
||||||
'New feedback message from Login page',
|
|
||||||
logger.GetColor('bluebg')
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
logger.Log(
|
|
||||||
'New feedback message from feedback page',
|
|
||||||
logger.GetColor('bluebg')
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
const user: User = req.session.user
|
|
||||||
|
|
||||||
utils.AppendToFile(
|
|
||||||
utils.GetDateString() +
|
|
||||||
':\n' +
|
|
||||||
JSON.stringify(
|
|
||||||
{
|
|
||||||
...req.body,
|
|
||||||
userID: user ? user.id : 'no user',
|
|
||||||
},
|
|
||||||
null,
|
|
||||||
2
|
|
||||||
),
|
|
||||||
msgFile
|
|
||||||
)
|
|
||||||
res.json({ success: true })
|
|
||||||
})
|
|
||||||
|
|
||||||
app.route('/fosuploader').post(function (req: Request, res: Response) {
|
app.route('/fosuploader').post(function (req: Request, res: Response) {
|
||||||
utils.uploadFile(req, uloadFiles).then(({ fileName }) => {
|
utils.uploadFile(req, uloadFiles).then(({ fileName }) => {
|
||||||
res.redirect('/f/' + fileName)
|
res.redirect('/f/' + fileName)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue