mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Added Request type with cookies and session, and fixed stuff that it broke
This commit is contained in:
parent
865e97a754
commit
3b902d736f
9 changed files with 117 additions and 95 deletions
|
@ -41,7 +41,7 @@ import auth from '../../middlewares/auth.middleware'
|
|||
import { dataToString, searchDatas } from '../../utils/classes'
|
||||
|
||||
import { SetupData } from '../../server'
|
||||
import { ModuleType, User, DataFile } from '../../types/basicTypes'
|
||||
import { ModuleType, User, DataFile, Request } from '../../types/basicTypes'
|
||||
|
||||
// files
|
||||
const msgFile = 'stats/msgs'
|
||||
|
@ -63,7 +63,7 @@ const addPWPerDay = 3 // every x day a user can give a pw
|
|||
const maxPWCount = 6 // maximum pw give opportunities a user can have at once
|
||||
const addPWCount = 1 // how many pw gen opportunities to add each time
|
||||
const daysAfterUserGetsPWs = 5 // days after user gets pw-s
|
||||
const minimumAlowwedSessions = 1 // how many sessions are allowed for a user
|
||||
const minimumAlowwedSessions = 2 // how many sessions are allowed for a user
|
||||
|
||||
// stuff gotten from server.js
|
||||
let userDB
|
||||
|
@ -261,7 +261,7 @@ function GetApp(): ModuleType {
|
|||
|
||||
// -------------------------------------------------------------
|
||||
|
||||
app.get('/getDbs', (req: any, res: any) => {
|
||||
app.get('/getDbs', (req: Request, res: any) => {
|
||||
logger.LogReq(req)
|
||||
|
||||
res.json(
|
||||
|
@ -274,10 +274,10 @@ function GetApp(): ModuleType {
|
|||
)
|
||||
})
|
||||
|
||||
app.get('/voteTodo', (req: any, res: any) => {
|
||||
app.get('/voteTodo', (req: Request, res: any) => {
|
||||
logger.LogReq(req)
|
||||
const userId = req.session.user.id
|
||||
const id = req.query.id
|
||||
const id: any = req.query.id
|
||||
const todos = utils.ReadJSON(todosFile)
|
||||
|
||||
if (!id) {
|
||||
|
@ -314,7 +314,7 @@ function GetApp(): ModuleType {
|
|||
})
|
||||
})
|
||||
|
||||
app.get('/todos', (req: any, res: any) => {
|
||||
app.get('/todos', (req: Request, res: any) => {
|
||||
logger.LogReq(req)
|
||||
const userId = req.session.user.id
|
||||
const todos = utils.ReadJSON(todosFile)
|
||||
|
@ -326,17 +326,17 @@ function GetApp(): ModuleType {
|
|||
})
|
||||
})
|
||||
|
||||
app.get('/ranklist', (req: any, res: any) => {
|
||||
app.get('/ranklist', (req: Request, res: any) => {
|
||||
logger.LogReq(req)
|
||||
let result
|
||||
let since = req.query.since
|
||||
const querySince: any = req.query.since
|
||||
const user: User = req.session.user
|
||||
|
||||
if (!since) {
|
||||
if (!querySince) {
|
||||
result = utils.ReadJSON(idStatFile)
|
||||
} else {
|
||||
try {
|
||||
since = new Date(since)
|
||||
const since = new Date(querySince)
|
||||
if (!(since instanceof Date) || isNaN(since.getTime())) {
|
||||
throw new Error('Not a date')
|
||||
}
|
||||
|
@ -396,16 +396,16 @@ function GetApp(): ModuleType {
|
|||
}
|
||||
|
||||
res.json({
|
||||
since: since,
|
||||
since: querySince,
|
||||
sum: sum,
|
||||
list: list,
|
||||
selfuserId: user.id,
|
||||
})
|
||||
})
|
||||
|
||||
app.get('/quickvote', (req: any, res: any) => {
|
||||
app.get('/quickvote', (req: Request, res: any) => {
|
||||
const key = req.query.key
|
||||
const val = req.query.val
|
||||
const val: any = req.query.val
|
||||
const user: User = req.session.user
|
||||
|
||||
if (!key || !val) {
|
||||
|
@ -479,7 +479,7 @@ function GetApp(): ModuleType {
|
|||
utils.WriteFile(JSON.stringify(voteData), voteFile)
|
||||
})
|
||||
|
||||
app.get('/avaiblePWS', (req: any, res: any) => {
|
||||
app.get('/avaiblePWS', (req: Request, res: any) => {
|
||||
logger.LogReq(req)
|
||||
|
||||
const user: User = req.session.user
|
||||
|
@ -497,7 +497,7 @@ function GetApp(): ModuleType {
|
|||
})
|
||||
})
|
||||
|
||||
app.post('/getpw', function(req: any, res: any) {
|
||||
app.post('/getpw', function(req: Request, res: any) {
|
||||
logger.LogReq(req)
|
||||
|
||||
const requestingUser = req.session.user
|
||||
|
@ -547,7 +547,7 @@ function GetApp(): ModuleType {
|
|||
})
|
||||
})
|
||||
|
||||
app.post('/getveteranpw', function(req: any, res: any) {
|
||||
app.post('/getveteranpw', function(req: Request, res: any) {
|
||||
logger.LogReq(req)
|
||||
const ip = req.headers['cf-connecting-ip'] || req.connection.remoteAddress
|
||||
const tries = dbtools.Select(userDB, 'veteranPWRequests', {
|
||||
|
@ -643,7 +643,7 @@ function GetApp(): ModuleType {
|
|||
}
|
||||
})
|
||||
|
||||
app.post('/login', (req: any, res: any) => {
|
||||
app.post('/login', (req: Request, res: any) => {
|
||||
logger.LogReq(req)
|
||||
const pw = req.body.pw
|
||||
? req.body.pw
|
||||
|
@ -744,7 +744,7 @@ function GetApp(): ModuleType {
|
|||
}
|
||||
})
|
||||
|
||||
app.post('/logout', (req: any, res: any) => {
|
||||
app.post('/logout', (req: Request, res: any) => {
|
||||
logger.LogReq(req)
|
||||
const sessionID = req.cookies.sessionID
|
||||
|
||||
|
@ -759,12 +759,12 @@ function GetApp(): ModuleType {
|
|||
|
||||
// --------------------------------------------------------------
|
||||
|
||||
app.get('/', function(req: any, res: any) {
|
||||
app.get('/', function(req: Request, res: any) {
|
||||
logger.LogReq(req)
|
||||
res.redirect('https://www.youtube.com/watch?v=ieqGJgqiXFk')
|
||||
res.redirect('https://www.youtube.com/watch?v=qLrnkK2YEcE')
|
||||
})
|
||||
|
||||
app.post('/postfeedbackfile', function(req: any, res: any) {
|
||||
app.post('/postfeedbackfile', function(req: Request, res: any) {
|
||||
UploadFile(req, res, uloadFiles, () => {
|
||||
res.json({ success: true })
|
||||
})
|
||||
|
@ -773,7 +773,7 @@ function GetApp(): ModuleType {
|
|||
logger.Log('New feedback file', logger.GetColor('bluebg'))
|
||||
})
|
||||
|
||||
app.post('/postfeedback', function(req: any, res: any) {
|
||||
app.post('/postfeedback', function(req: Request, res: any) {
|
||||
logger.LogReq(req)
|
||||
if (req.body.fromLogin) {
|
||||
logger.Log(
|
||||
|
@ -803,7 +803,7 @@ function GetApp(): ModuleType {
|
|||
res.json({ success: true })
|
||||
})
|
||||
|
||||
function UploadFile(req: any, res: any, path, next) {
|
||||
function UploadFile(req: Request, res: any, path, next) {
|
||||
try {
|
||||
req.pipe(req.busboy)
|
||||
req.busboy.on('file', function(fieldname, file, filename) {
|
||||
|
@ -840,20 +840,21 @@ function GetApp(): ModuleType {
|
|||
}
|
||||
}
|
||||
|
||||
app.route('/fosuploader').post(function(req: any, res: any) {
|
||||
app.route('/fosuploader').post(function(req: Request, res: any) {
|
||||
UploadFile(req, res, uloadFiles, (fn) => {
|
||||
res.redirect('/f/' + fn)
|
||||
})
|
||||
})
|
||||
|
||||
app.route('/badtestsender').post(function(req: any, res: any) {
|
||||
app.route('/badtestsender').post(function(req: Request, res: any) {
|
||||
UploadFile(req, res, recivedFiles, () => {
|
||||
res.redirect('back')
|
||||
})
|
||||
logger.LogReq(req)
|
||||
})
|
||||
|
||||
app.get('/allqr.txt', function(req: any, res: any) {
|
||||
app.get('/allqr.txt', function(req: Request, res: any) {
|
||||
// TODO: if dataId param exists download only that db
|
||||
res.set('Content-Type', 'text/plain')
|
||||
const stringifiedData = questionDbs.map((qdb) => {
|
||||
let result = ''
|
||||
|
@ -872,7 +873,7 @@ function GetApp(): ModuleType {
|
|||
// -------------------------------------------------------------------------------------------
|
||||
// API
|
||||
|
||||
app.post('/uploaddata', (req: any, res: any) => {
|
||||
app.post('/uploaddata', (req: Request, res: any) => {
|
||||
// body: JSON.stringify({
|
||||
// newData: data,
|
||||
// count: getCount(data),
|
||||
|
@ -979,7 +980,7 @@ function GetApp(): ModuleType {
|
|||
}
|
||||
})
|
||||
|
||||
app.post('/isAdding', function(req: any, res: any) {
|
||||
app.post('/isAdding', function(req: Request, res: any) {
|
||||
logger.LogReq(req)
|
||||
const user: User = req.session.user
|
||||
const dryRun = testUsers.includes(user.id)
|
||||
|
@ -1015,7 +1016,7 @@ function GetApp(): ModuleType {
|
|||
}
|
||||
})
|
||||
|
||||
app.get('/ask', function(req: any, res) {
|
||||
app.get('/ask', function(req: Request, res) {
|
||||
if (Object.keys(req.query).length === 0) {
|
||||
logger.DebugLog(`No query params`, 'ask', 1)
|
||||
res.json({
|
||||
|
@ -1026,7 +1027,7 @@ function GetApp(): ModuleType {
|
|||
})
|
||||
} else {
|
||||
if (req.query.q && req.query.data) {
|
||||
const subj = req.query.subj || ''
|
||||
const subj: any = req.query.subj || ''
|
||||
const question = req.query.q
|
||||
const recData: any = req.query.data
|
||||
|
||||
|
@ -1124,7 +1125,7 @@ function GetApp(): ModuleType {
|
|||
})
|
||||
}
|
||||
|
||||
app.get('/datacount', function(req: any, res: any) {
|
||||
app.get('/datacount', function(req: Request, res: any) {
|
||||
logger.LogReq(req)
|
||||
if (req.query.detailed === 'all') {
|
||||
res.json({
|
||||
|
@ -1138,7 +1139,7 @@ function GetApp(): ModuleType {
|
|||
}
|
||||
})
|
||||
|
||||
app.get('/infos', function(req: any, res) {
|
||||
app.get('/infos', function(req: Request, res) {
|
||||
const user: User = req.session.user
|
||||
|
||||
const result: any = {
|
||||
|
@ -1163,11 +1164,11 @@ function GetApp(): ModuleType {
|
|||
|
||||
// -------------------------------------------------------------------------------------------
|
||||
|
||||
app.get('*', function(req: any, res: any) {
|
||||
app.get('*', function(req: Request, res: any) {
|
||||
res.status(404).render('404')
|
||||
})
|
||||
|
||||
app.post('*', function(req: any, res: any) {
|
||||
app.post('*', function(req: Request, res: any) {
|
||||
res.status(404).render('404')
|
||||
})
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue