mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Logging fixes / imporvements, voteTodo api
This commit is contained in:
parent
4e34267d44
commit
865e97a754
6 changed files with 66 additions and 38 deletions
|
@ -3,7 +3,6 @@ module.exports = {
|
|||
browser: true,
|
||||
es6: true,
|
||||
node: true,
|
||||
jest: true,
|
||||
},
|
||||
parser: '@typescript-eslint/parser',
|
||||
plugins: ['@typescript-eslint'],
|
||||
|
@ -29,7 +28,8 @@ module.exports = {
|
|||
'@typescript-eslint/ban-types': 'off',
|
||||
'id-length': [
|
||||
'warn',
|
||||
{ exceptions: ['i', 'j', 't', 'Q', 'A', 'C', 'q', 'a', 'b'] },
|
||||
{ exceptions: ['i', 'j', 't', 'Q', 'A', 'C', 'q', 'a', 'b', 'x'] },
|
||||
],
|
||||
},
|
||||
root: true
|
||||
}
|
||||
|
|
|
@ -128,6 +128,7 @@ function jsonStats() {
|
|||
-e "s,/install,${P}&${NC},g" \
|
||||
-e "s,/irc,${P}&${NC},g" \
|
||||
-e "s,/postfeedback,${P}&${NC},g" \
|
||||
-e "s,/voteTodo,${P}&${NC},g" \
|
||||
-e "s,/quickvote,${P}&${NC},g" \
|
||||
-e "s,/servergit,${P}&${NC},g" \
|
||||
-e "s,/scriptgit,${P}&${NC},g" \
|
||||
|
|
|
@ -8,6 +8,13 @@ interface Options {
|
|||
exceptions: Array<string>
|
||||
}
|
||||
|
||||
const testUser = {
|
||||
id: 19,
|
||||
avaiblePWRequests: 999,
|
||||
pwRequestCount: 19,
|
||||
created: new Date(),
|
||||
}
|
||||
|
||||
export default function(options: Options): any {
|
||||
const { userDB, jsonResponse, exceptions } = options
|
||||
|
||||
|
@ -34,9 +41,7 @@ export default function(options: Options): any {
|
|||
|
||||
if (process.env.NS_NOUSER) {
|
||||
req.session = {
|
||||
user: {
|
||||
id: 19,
|
||||
},
|
||||
user: testUser,
|
||||
sessionID: sessionID || 111111111111111111,
|
||||
isException: false,
|
||||
}
|
||||
|
|
|
@ -274,7 +274,7 @@ function GetApp(): ModuleType {
|
|||
)
|
||||
})
|
||||
|
||||
app.get('/updateTodo', (req: any, res: any) => {
|
||||
app.get('/voteTodo', (req: any, res: any) => {
|
||||
logger.LogReq(req)
|
||||
const userId = req.session.user.id
|
||||
const id = req.query.id
|
||||
|
@ -1028,20 +1028,26 @@ function GetApp(): ModuleType {
|
|||
if (req.query.q && req.query.data) {
|
||||
const subj = req.query.subj || ''
|
||||
const question = req.query.q
|
||||
let recData: any = {}
|
||||
try {
|
||||
recData = JSON.parse(req.query.data)
|
||||
} catch (error) {
|
||||
logger.Log(
|
||||
`Unable to parse recieved question data! '${req.query.data}'`,
|
||||
logger.GetColor('redbg')
|
||||
)
|
||||
}
|
||||
const recData: any = req.query.data
|
||||
|
||||
searchDatas(questionDbs, question, subj, recData)
|
||||
.then((result) => {
|
||||
try {
|
||||
const mergedResult = result.reduce((acc, dbRes) => {
|
||||
return [...acc, ...dbRes.result]
|
||||
}, [])
|
||||
const sortedResult = mergedResult.sort((q1, q2) => {
|
||||
if (q1.match < q2.match) {
|
||||
return 1
|
||||
} else if (q1.match > q2.match) {
|
||||
return -1
|
||||
} else {
|
||||
return 0
|
||||
}
|
||||
})
|
||||
|
||||
res.json({
|
||||
result: result,
|
||||
result: sortedResult,
|
||||
success: true,
|
||||
})
|
||||
logger.DebugLog(
|
||||
|
@ -1050,6 +1056,13 @@ function GetApp(): ModuleType {
|
|||
1
|
||||
)
|
||||
logger.DebugLog(result, 'ask', 2)
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
logger.Log(
|
||||
'Error while sending ask results',
|
||||
logger.GetColor('redbg')
|
||||
)
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
logger.Log('Search Data error!', logger.GetColor('redbg'))
|
||||
|
@ -1099,12 +1112,15 @@ function GetApp(): ModuleType {
|
|||
|
||||
function getDetailedRes() {
|
||||
return questionDbs.map((qdb) => {
|
||||
return qdb.data.map((subj) => {
|
||||
return {
|
||||
dbName: qdb.name,
|
||||
subjs: qdb.data.map((subj) => {
|
||||
return {
|
||||
name: subj.Name,
|
||||
count: subj.Questions.length,
|
||||
}
|
||||
})
|
||||
}),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -152,7 +152,7 @@ const cookieSecret = uuidv4()
|
|||
app.use(cookieParser(cookieSecret))
|
||||
app.use(
|
||||
reqlogger({
|
||||
loggableKeywords: ['stable.user.js'],
|
||||
loggableKeywords: [],
|
||||
loggableModules: ['dataeditor'],
|
||||
})
|
||||
)
|
||||
|
|
|
@ -112,7 +112,7 @@ function Log(msg: string | object, color?: string): void {
|
|||
function LogReq(
|
||||
req: any /*express.Request*/,
|
||||
toFile?: boolean,
|
||||
sc?: string
|
||||
statusCode?: string
|
||||
): void {
|
||||
try {
|
||||
const ip = req.headers['cf-connecting-ip'] || req.connection.remoteAddress
|
||||
|
@ -124,7 +124,7 @@ function LogReq(
|
|||
return
|
||||
}
|
||||
|
||||
let logEntry = GetRandomColor(ip) + ip + C()
|
||||
let logEntry = logHashed(ip)
|
||||
let dl = DELIM
|
||||
if (req.url.includes('lred')) {
|
||||
dl += C('red')
|
||||
|
@ -141,7 +141,13 @@ function LogReq(
|
|||
)
|
||||
}
|
||||
logEntry +=
|
||||
dl + hostname + dl + req.headers['user-agent'] + dl + req.method + dl
|
||||
dl +
|
||||
logHashed(hostname) +
|
||||
dl +
|
||||
req.headers['user-agent'] +
|
||||
dl +
|
||||
req.method +
|
||||
dl
|
||||
|
||||
if (req.session && req.session.user) {
|
||||
logEntry += C('cyan') + req.session.user.id + C() + dl
|
||||
|
@ -153,8 +159,8 @@ function LogReq(
|
|||
|
||||
logEntry += GetRandomColor(req.url.split('?')[0]) + req.url
|
||||
|
||||
if (sc !== undefined) {
|
||||
logEntry += dl + sc
|
||||
if (statusCode !== undefined) {
|
||||
logEntry += dl + statusCode
|
||||
}
|
||||
|
||||
logEntry += C()
|
||||
|
@ -385,7 +391,7 @@ function C(color?: string): string {
|
|||
if (color === 'magenta') {
|
||||
return '\x1b[35m'
|
||||
}
|
||||
if (color === 'coloryan') {
|
||||
if (color === 'cyan') {
|
||||
return '\x1b[36m'
|
||||
}
|
||||
return '\x1b[0m'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue