mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2026-04-28 03:07:38 +02:00
90 lines
2.5 KiB
TypeScript
90 lines
2.5 KiB
TypeScript
/* ----------------------------------------------------------------------------
|
|
|
|
Question Server
|
|
GitLab: <https://gitlab.com/MrFry/mrfrys-node-server>
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
------------------------------------------------------------------------- */
|
|
|
|
import { Response } from 'express'
|
|
|
|
import logger from '../../../utils/logger'
|
|
import utils from '../../../utils/utils'
|
|
import { Request, SubmoduleData, User } from '../../../types/basicTypes'
|
|
|
|
const msgFile = 'stats/msgs'
|
|
const uloadFiles = 'data/f'
|
|
|
|
function setup(data: SubmoduleData): void {
|
|
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) {
|
|
utils.uploadFile(req, uloadFiles).then(({ fileName }) => {
|
|
res.redirect('/f/' + fileName)
|
|
})
|
|
})
|
|
}
|
|
|
|
export default {
|
|
setup: setup,
|
|
}
|