mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Merge branch 'master' of gitlab.com:MrFry/mrfrys-node-server
This commit is contained in:
commit
cf028489c3
4 changed files with 119 additions and 11 deletions
|
@ -39,6 +39,8 @@ const passwordFile = 'data/dataEditorPasswords.json'
|
||||||
const dataEditsLog = 'stats/dataEdits'
|
const dataEditsLog = 'stats/dataEdits'
|
||||||
const dailyDataCountFile = 'stats/dailyDataCount'
|
const dailyDataCountFile = 'stats/dailyDataCount'
|
||||||
const usersDbBackupPath = 'data/dbs/backup'
|
const usersDbBackupPath = 'data/dbs/backup'
|
||||||
|
const quickVoteResultsDir = 'stats/qvote'
|
||||||
|
const quickVotes = 'stats/qvote/votes.json'
|
||||||
|
|
||||||
// other constants
|
// other constants
|
||||||
const maxVeteranPwGetCount = 10
|
const maxVeteranPwGetCount = 10
|
||||||
|
@ -129,6 +131,73 @@ function GetApp () {
|
||||||
|
|
||||||
// -------------------------------------------------------------
|
// -------------------------------------------------------------
|
||||||
|
|
||||||
|
app.get('/quickvote', (req, res) => {
|
||||||
|
const key = req.query.key
|
||||||
|
const val = req.query.val
|
||||||
|
|
||||||
|
if (!key || !val) {
|
||||||
|
res.render('votethank', {
|
||||||
|
results: 'error',
|
||||||
|
msg: 'no key or val query param!'
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let votes = {}
|
||||||
|
if (utils.FileExists(quickVotes)) {
|
||||||
|
votes = utils.ReadJSON(quickVotes)
|
||||||
|
} else {
|
||||||
|
res.render('votethank', {
|
||||||
|
result: 'no such pool'
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!votes.voteNames.includes(key)) {
|
||||||
|
res.render('votethank', {
|
||||||
|
result: 'no such pool'
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const voteFile = quickVoteResultsDir + '/' + key + '.json'
|
||||||
|
const user = req.session.user
|
||||||
|
|
||||||
|
let voteData = {
|
||||||
|
votes: {},
|
||||||
|
users: []
|
||||||
|
}
|
||||||
|
|
||||||
|
if (utils.FileExists(voteFile)) {
|
||||||
|
voteData = utils.ReadJSON(voteFile)
|
||||||
|
} else {
|
||||||
|
utils.CreatePath(quickVoteResultsDir)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!voteData.users.includes(user.id)) {
|
||||||
|
if (voteData[val]) {
|
||||||
|
voteData.votes[val]++
|
||||||
|
} else {
|
||||||
|
voteData.votes[val] = 1
|
||||||
|
}
|
||||||
|
voteData.users.push(user.id)
|
||||||
|
|
||||||
|
logger.Log(`Vote from #${user.id}: ${key}: ${val}`, logger.GetColor('blue'))
|
||||||
|
res.render('votethank', {
|
||||||
|
result: 'success',
|
||||||
|
msg: 'vote added'
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
logger.Log(`#${user.id} already voted for: ${key}: ${val}`, logger.GetColor('blue'))
|
||||||
|
res.render('votethank', {
|
||||||
|
result: 'already voted',
|
||||||
|
msg: 'already voted'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
utils.WriteFile(JSON.stringify(voteData), voteFile)
|
||||||
|
})
|
||||||
|
|
||||||
app.get('/avaiblePWS', (req, res) => {
|
app.get('/avaiblePWS', (req, res) => {
|
||||||
logger.LogReq(req)
|
logger.LogReq(req)
|
||||||
|
|
||||||
|
|
31
modules/api/views/votethank.ejs
Executable file
31
modules/api/views/votethank.ejs
Executable file
|
@ -0,0 +1,31 @@
|
||||||
|
<html>
|
||||||
|
<body bgcolor="#212127">
|
||||||
|
<head>
|
||||||
|
<title>Shit uploader</title>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<style>
|
||||||
|
.main {
|
||||||
|
font-size: 28px;
|
||||||
|
color: #ffffff;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<div class='main'>
|
||||||
|
<%
|
||||||
|
if (result == 'success') {
|
||||||
|
%> ty a szavazásért c: <%
|
||||||
|
} else if (result == 'no such pool') {
|
||||||
|
%> Ilyen nevű szavazás nincs :c <%
|
||||||
|
} else if (result == 'already voted') {
|
||||||
|
%> Már szavaztál, de azért ty c: <%
|
||||||
|
} else if (result == 'error') {
|
||||||
|
%> Helytelen url paraméterek :c <%
|
||||||
|
} else {
|
||||||
|
%> bit of a fuckup here <%
|
||||||
|
}
|
||||||
|
%>
|
||||||
|
ty c:
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
22
server.js
22
server.js
|
@ -89,18 +89,20 @@ function exit (reason) {
|
||||||
|
|
||||||
const app = express()
|
const app = express()
|
||||||
|
|
||||||
app.use(function (req, res, next) {
|
if (!process.env.NS_DEVEL) {
|
||||||
if (req.secure) {
|
app.use(function (req, res, next) {
|
||||||
next()
|
if (req.secure) {
|
||||||
} else {
|
next()
|
||||||
logger.DebugLog(`HTTPS ${req.method} redirect to: ${'https://' + req.headers.host + req.url}`, 'https', 1)
|
|
||||||
if (req.method === 'POST') {
|
|
||||||
res.redirect(307, 'https://' + req.headers.host + req.url)
|
|
||||||
} else {
|
} else {
|
||||||
res.redirect('https://' + req.headers.host + req.url)
|
logger.DebugLog(`HTTPS ${req.method} redirect to: ${'https://' + req.headers.host + req.url}`, 'https', 1)
|
||||||
|
if (req.method === 'POST') {
|
||||||
|
res.redirect(307, 'https://' + req.headers.host + req.url)
|
||||||
|
} else {
|
||||||
|
res.redirect('https://' + req.headers.host + req.url)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
})
|
}
|
||||||
// https://github.com/expressjs/cors#configuration-options
|
// https://github.com/expressjs/cors#configuration-options
|
||||||
app.use(cors({
|
app.use(cors({
|
||||||
credentials: true,
|
credentials: true,
|
||||||
|
|
|
@ -101,7 +101,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div id='form'>
|
<div id='form'>
|
||||||
<div class='inputContainer'>
|
<div class='inputContainer'>
|
||||||
<input type='text' id='pw' name='pw' autocomplete="off" autofocus/>
|
<input onkeyup="PWKeyUp(this)" type='text' id='pw' name='pw' autocomplete="off" autofocus/>
|
||||||
<input type='hidden' id='cid' name='pw' autocomplete="off"/>
|
<input type='hidden' id='cid' name='pw' autocomplete="off"/>
|
||||||
</div>
|
</div>
|
||||||
<div class='ircLinkContainer' >
|
<div class='ircLinkContainer' >
|
||||||
|
@ -112,6 +112,12 @@
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
<script>
|
<script>
|
||||||
|
function PWKeyUp (inputField) {
|
||||||
|
if (event.keyCode === 13) {
|
||||||
|
event.preventDefault();
|
||||||
|
Login(document.getElementById('sendButton'))
|
||||||
|
}
|
||||||
|
}
|
||||||
function HandleFeedbackResp (resp) {
|
function HandleFeedbackResp (resp) {
|
||||||
document.getElementById('sendButton').innerText = 'Submit'
|
document.getElementById('sendButton').innerText = 'Submit'
|
||||||
const textNode = document.getElementById('text')
|
const textNode = document.getElementById('text')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue