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) {
|
||||
res.status(401) // Unauthorized
|
||||
if (req.is('application/json')) {
|
||||
if (req.headers['content-type'] === 'application/json') {
|
||||
res.json({
|
||||
result: 'nouser',
|
||||
msg: 'You are not logged in',
|
||||
})
|
||||
return
|
||||
} else {
|
||||
res.render('login')
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -533,7 +533,7 @@ function setup(data: SubmoduleData): Submodule {
|
|||
}
|
||||
|
||||
function getNewUsersSince(since: number) {
|
||||
const users = dbtools.runStatement(
|
||||
const users: User[] = dbtools.runStatement(
|
||||
userDB,
|
||||
`SELECT *
|
||||
FROM users
|
||||
|
@ -774,6 +774,8 @@ function setup(data: SubmoduleData): Submodule {
|
|||
}
|
||||
const newUserCount = dbtools.SelectAll(userDB, 'users').length
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------
|
||||
|
||||
const hasNewData = resultData.length > 0
|
||||
if (!hasNewData) {
|
||||
logger.Log(
|
||||
|
@ -996,6 +998,7 @@ function setup(data: SubmoduleData): Submodule {
|
|||
}
|
||||
|
||||
let hostToLog = remoteHost || 'Unknown host'
|
||||
let sentUsers = 0
|
||||
if (remoteHost) {
|
||||
const remotePeerInfo = peers.find((peer) => {
|
||||
return peerToString(peer) === remoteHost
|
||||
|
@ -1006,12 +1009,14 @@ function setup(data: SubmoduleData): Submodule {
|
|||
if (remotePublicKey) {
|
||||
// FIXME: sign data?
|
||||
const newUsers = getNewUsersSince(since)
|
||||
sentUsers = newUsers.length
|
||||
result.encryptedUsers = encrypt(
|
||||
remotePublicKey,
|
||||
JSON.stringify(newUsers)
|
||||
)
|
||||
// TODO: count sent user count
|
||||
logger.Log(
|
||||
`Sending new users to "${remoteHost}" (encrypted)`,
|
||||
`\tSending new users to "${remoteHost}" (encrypted)`,
|
||||
'green'
|
||||
)
|
||||
} else if (remotePeerInfo) {
|
||||
|
@ -1045,13 +1050,26 @@ function setup(data: SubmoduleData): Submodule {
|
|||
? 'all time'
|
||||
: new Date(since).toLocaleString()
|
||||
|
||||
// TODO: count sent data
|
||||
logger.Log(
|
||||
`Sending new data to ${logger.C(
|
||||
`\tSending new data to ${logger.C(
|
||||
'blue'
|
||||
)}${hostToLog}${logger.C()} since ${logger.C(
|
||||
'blue'
|
||||
)}${dateToLog}${logger.C()} `
|
||||
)
|
||||
logger.logTable(
|
||||
[
|
||||
['Users', 'QDBs', 'Subjs', 'Questions'],
|
||||
[
|
||||
sentUsers,
|
||||
questionDbsWithNewQuestions.length,
|
||||
subjects,
|
||||
questions,
|
||||
],
|
||||
],
|
||||
{ rowPrefix: '\t' }
|
||||
)
|
||||
|
||||
res.json(result)
|
||||
})
|
||||
|
|
|
@ -264,7 +264,7 @@ Object.keys(modules).forEach(function (key) {
|
|||
})
|
||||
|
||||
app.get('*', (req, res) => {
|
||||
if (req.is('application/json')) {
|
||||
if (req.headers['content-type'] === 'application/json') {
|
||||
res.status(404).end()
|
||||
} else {
|
||||
res.status(404).render('404')
|
||||
|
@ -272,7 +272,7 @@ app.get('*', (req, res) => {
|
|||
})
|
||||
|
||||
app.post('*', (req, res) => {
|
||||
if (req.is('application/json')) {
|
||||
if (req.headers['content-type'] === 'application/json') {
|
||||
res.status(404).end()
|
||||
} else {
|
||||
res.status(404).render('404')
|
||||
|
|
|
@ -88,7 +88,6 @@ export interface QuestionDb extends DataFile {
|
|||
export interface User {
|
||||
id: number
|
||||
pw: string
|
||||
oldCID?: number
|
||||
notes?: string
|
||||
loginCount: number
|
||||
avaiblePWRequests: number
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue