diff --git a/server.js b/server.js
index 18693fc..70823b8 100644
--- a/server.js
+++ b/server.js
@@ -1,139 +1,142 @@
/* eslint-env node, es6 */
const express = require('express');
// bot framework for interacting with the wiki, see https://www.npmjs.com/package/mwn
const { mwn } = require('mwn');
// sql client for database accesses, see https://www.npmjs.com/package/mysql2
// const mysql = require('mysql2/promise');
// bot account and database access credentials, if needed
const crendentials = require('../credentials.json');
const app = express();
app.use(express.json()); // for parsing the body of POST requests
app.use(express.static('static')); // serve files in the static directory
const port = parseInt(process.env.PORT, 10); // necessary for the tool to be discovered by the nginx proxy
// You may want to sign in with a bot account if you want to make use of high bot
// API limits, otherwise just remove the username and password fields below.
const client = new mwn({
apiUrl: 'https://hr.wikipedia.org/w/api.php',
username: crendentials.bot_username,
password: crendentials.bot_password
});
/* async function getDbConnection() {
return await mysql.createConnection({
host: 'enwiki.analytics.db.svc.eqiad.wmflabs',
port: 3306,
user: crendentials.db_user,
password: crendentials.db_password,
database: 'enwiki_p'
});
}*/
(async function () {
// need to do either a .getSiteInfo() or .login() before we can use the client object
await client.login();
await client.getSiteInfo();
// Serve index.html as the homepage
app.get('/', (req, res) => {
res.sendFile(__dirname + '/static/index.html');
});
app.get('/patrol', (req, res) => {
var a = 'Danas je ' + konverzijaDatuma(new Date()) + '
'
client.request({
"action": "query",
format: "json",
list: "recentchanges",
utf8: 1,
rcdir: "older",
rcprop: "patrolled|user|timestamp|ids",
rcshow: "unpatrolled",
rclimit: "max",
}).then((data) => {
data.query.recentchanges.sort(function (a, b) {
return (a.revid < b.revid) ? -1 : ((a.revid > b.revid) ? 1 : 0);
});
a = a + 'Pronađeno ' + data.query.recentchanges.length + ' neophođenih izmjena.
'
var izmjene_ip = [];
var izmjene = [];
var stranice_ip = [];
var stranice = [];
data.query.recentchanges.forEach(function (e) {
if ("anon" in e) {
if (e.type == 'edit') {
izmjene_ip.push(e);
} else {
stranice_ip.push(e);
}
}
else {
if (e.type == 'edit') {
izmjene.push(e);
} else {
stranice.push(e);
}
}
});
a = a + 'Prijavljeni: ' + izmjene.length + ' neophođenih uređivanja (najstarija ' + konverzijaDatuma(izmjene[0].timestamp) + ') i ' + stranice.length + ' neophođenih stranica (najstarija ' + konverzijaDatuma(stranice[0].timestamp) + ')
'
a = a + 'Neprijavljeni: ' + izmjene_ip.length + ' neophođenih uređivanja (najstarija ' + konverzijaDatuma(izmjene_ip[0].timestamp) + ') i ' + stranice_ip.length + ' neophođenih stranica (najstarija ' + konverzijaDatuma(stranice_ip[0].timestamp) + ')
'
res.send(a);
});
});
/* app.get('/get_endpoint', (req, res) => {
// req.query gives the GET parameters
res.send('Hello World!');
});
app.post('/post_endpoint', (req, res) => {
// req.body gives the POST body
res.send('Hello World!');
});
// Sample GET endpoint that returns the wikitext of a specified page
app.get('/read_wiki_page', (req, res) => {
var page_name = req.query.page;
client.read(page_name).then(pg => {
var page_text = pg.revisions[0].content;
res.send(page_text);
});
});
*/
app.listen(port, () => console.log(`Example app listening at port ${port}`));
})();
function konverzijaDatuma(datumRaw) {
const monthNames = ["siječnja", "veljače", "ožujka", "travnja", "svibnja", "lipnja",
"srpnja", "kolovoza", "rujna", "listopada", "studenoga", "prosinca"
];
datum = new Date(datumRaw);
var weekday = datum.toLocaleString(
- 'default', { weekday: 'long' }
+ 'hr-HR', {
+ weekday: 'long',
+ timeZone: 'Europe/Zagreb'
+ }
);
return weekday + ', ' + datum.getDate() + '. ' + monthNames[datum.getMonth()] + ' ' + datum.getFullYear()
+ '. ' + datum.toLocaleTimeString()
}