diff --git a/.eslintrc.js b/.eslintrc.js index 79c8e94..7b9d2a2 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -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 } diff --git a/scripts/serverStats.sh b/scripts/serverStats.sh index 1a7ad92..810cf1a 100755 --- a/scripts/serverStats.sh +++ b/scripts/serverStats.sh @@ -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" \ diff --git a/src/middlewares/auth.middleware.ts b/src/middlewares/auth.middleware.ts index 6954d50..8d1d13a 100644 --- a/src/middlewares/auth.middleware.ts +++ b/src/middlewares/auth.middleware.ts @@ -8,6 +8,13 @@ interface Options { exceptions: Array } +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, } diff --git a/src/modules/api/api.ts b/src/modules/api/api.ts index 242cac8..69f0931 100644 --- a/src/modules/api/api.ts +++ b/src/modules/api/api.ts @@ -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,28 +1028,41 @@ 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) => { - res.json({ - result: result, - success: true, - }) - logger.DebugLog( - `Question result length: ${result.length}`, - 'ask', - 1 - ) - logger.DebugLog(result, 'ask', 2) + 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: sortedResult, + success: true, + }) + logger.DebugLog( + `Question result length: ${result.length}`, + 'ask', + 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 { - name: subj.Name, - count: subj.Questions.length, - } - }) + return { + dbName: qdb.name, + subjs: qdb.data.map((subj) => { + return { + name: subj.Name, + count: subj.Questions.length, + } + }), + } }) } diff --git a/src/server.ts b/src/server.ts index 55fe9c3..9406ee4 100755 --- a/src/server.ts +++ b/src/server.ts @@ -152,7 +152,7 @@ const cookieSecret = uuidv4() app.use(cookieParser(cookieSecret)) app.use( reqlogger({ - loggableKeywords: ['stable.user.js'], + loggableKeywords: [], loggableModules: ['dataeditor'], }) ) diff --git a/src/utils/logger.ts b/src/utils/logger.ts index c682e9f..a0f2b23 100755 --- a/src/utils/logger.ts +++ b/src/utils/logger.ts @@ -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'