mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2026-04-28 19:27:38 +02:00
Feedback goes to chat
This commit is contained in:
@@ -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) => {
|
||||
const user: User = req.session.user
|
||||
const userid: number = user.id
|
||||
|
||||
Reference in New Issue
Block a user