mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
fixed content type check, added bit more logging on getnewdata since ep
This commit is contained in:
parent
b1e89249b4
commit
f1a88b7ff5
4 changed files with 26 additions and 7 deletions
|
@ -53,13 +53,15 @@ export const testUser: User = {
|
||||||
|
|
||||||
function renderLogin(req: Request, res: Response) {
|
function renderLogin(req: Request, res: Response) {
|
||||||
res.status(401) // Unauthorized
|
res.status(401) // Unauthorized
|
||||||
if (req.is('application/json')) {
|
if (req.headers['content-type'] === 'application/json') {
|
||||||
res.json({
|
res.json({
|
||||||
result: 'nouser',
|
result: 'nouser',
|
||||||
msg: 'You are not logged in',
|
msg: 'You are not logged in',
|
||||||
})
|
})
|
||||||
|
return
|
||||||
} else {
|
} else {
|
||||||
res.render('login')
|
res.render('login')
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -533,7 +533,7 @@ function setup(data: SubmoduleData): Submodule {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getNewUsersSince(since: number) {
|
function getNewUsersSince(since: number) {
|
||||||
const users = dbtools.runStatement(
|
const users: User[] = dbtools.runStatement(
|
||||||
userDB,
|
userDB,
|
||||||
`SELECT *
|
`SELECT *
|
||||||
FROM users
|
FROM users
|
||||||
|
@ -774,6 +774,8 @@ function setup(data: SubmoduleData): Submodule {
|
||||||
}
|
}
|
||||||
const newUserCount = dbtools.SelectAll(userDB, 'users').length
|
const newUserCount = dbtools.SelectAll(userDB, 'users').length
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
const hasNewData = resultData.length > 0
|
const hasNewData = resultData.length > 0
|
||||||
if (!hasNewData) {
|
if (!hasNewData) {
|
||||||
logger.Log(
|
logger.Log(
|
||||||
|
@ -996,6 +998,7 @@ function setup(data: SubmoduleData): Submodule {
|
||||||
}
|
}
|
||||||
|
|
||||||
let hostToLog = remoteHost || 'Unknown host'
|
let hostToLog = remoteHost || 'Unknown host'
|
||||||
|
let sentUsers = 0
|
||||||
if (remoteHost) {
|
if (remoteHost) {
|
||||||
const remotePeerInfo = peers.find((peer) => {
|
const remotePeerInfo = peers.find((peer) => {
|
||||||
return peerToString(peer) === remoteHost
|
return peerToString(peer) === remoteHost
|
||||||
|
@ -1006,12 +1009,14 @@ function setup(data: SubmoduleData): Submodule {
|
||||||
if (remotePublicKey) {
|
if (remotePublicKey) {
|
||||||
// FIXME: sign data?
|
// FIXME: sign data?
|
||||||
const newUsers = getNewUsersSince(since)
|
const newUsers = getNewUsersSince(since)
|
||||||
|
sentUsers = newUsers.length
|
||||||
result.encryptedUsers = encrypt(
|
result.encryptedUsers = encrypt(
|
||||||
remotePublicKey,
|
remotePublicKey,
|
||||||
JSON.stringify(newUsers)
|
JSON.stringify(newUsers)
|
||||||
)
|
)
|
||||||
|
// TODO: count sent user count
|
||||||
logger.Log(
|
logger.Log(
|
||||||
`Sending new users to "${remoteHost}" (encrypted)`,
|
`\tSending new users to "${remoteHost}" (encrypted)`,
|
||||||
'green'
|
'green'
|
||||||
)
|
)
|
||||||
} else if (remotePeerInfo) {
|
} else if (remotePeerInfo) {
|
||||||
|
@ -1045,13 +1050,26 @@ function setup(data: SubmoduleData): Submodule {
|
||||||
? 'all time'
|
? 'all time'
|
||||||
: new Date(since).toLocaleString()
|
: new Date(since).toLocaleString()
|
||||||
|
|
||||||
|
// TODO: count sent data
|
||||||
logger.Log(
|
logger.Log(
|
||||||
`Sending new data to ${logger.C(
|
`\tSending new data to ${logger.C(
|
||||||
'blue'
|
'blue'
|
||||||
)}${hostToLog}${logger.C()} since ${logger.C(
|
)}${hostToLog}${logger.C()} since ${logger.C(
|
||||||
'blue'
|
'blue'
|
||||||
)}${dateToLog}${logger.C()} `
|
)}${dateToLog}${logger.C()} `
|
||||||
)
|
)
|
||||||
|
logger.logTable(
|
||||||
|
[
|
||||||
|
['Users', 'QDBs', 'Subjs', 'Questions'],
|
||||||
|
[
|
||||||
|
sentUsers,
|
||||||
|
questionDbsWithNewQuestions.length,
|
||||||
|
subjects,
|
||||||
|
questions,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
{ rowPrefix: '\t' }
|
||||||
|
)
|
||||||
|
|
||||||
res.json(result)
|
res.json(result)
|
||||||
})
|
})
|
||||||
|
|
|
@ -264,7 +264,7 @@ Object.keys(modules).forEach(function (key) {
|
||||||
})
|
})
|
||||||
|
|
||||||
app.get('*', (req, res) => {
|
app.get('*', (req, res) => {
|
||||||
if (req.is('application/json')) {
|
if (req.headers['content-type'] === 'application/json') {
|
||||||
res.status(404).end()
|
res.status(404).end()
|
||||||
} else {
|
} else {
|
||||||
res.status(404).render('404')
|
res.status(404).render('404')
|
||||||
|
@ -272,7 +272,7 @@ app.get('*', (req, res) => {
|
||||||
})
|
})
|
||||||
|
|
||||||
app.post('*', (req, res) => {
|
app.post('*', (req, res) => {
|
||||||
if (req.is('application/json')) {
|
if (req.headers['content-type'] === 'application/json') {
|
||||||
res.status(404).end()
|
res.status(404).end()
|
||||||
} else {
|
} else {
|
||||||
res.status(404).render('404')
|
res.status(404).render('404')
|
||||||
|
|
|
@ -88,7 +88,6 @@ export interface QuestionDb extends DataFile {
|
||||||
export interface User {
|
export interface User {
|
||||||
id: number
|
id: number
|
||||||
pw: string
|
pw: string
|
||||||
oldCID?: number
|
|
||||||
notes?: string
|
notes?: string
|
||||||
loginCount: number
|
loginCount: number
|
||||||
avaiblePWRequests: number
|
avaiblePWRequests: number
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue