prettyify code
This commit is contained in:
96
lib/app.js
96
lib/app.js
@ -1,87 +1,99 @@
|
||||
const Database = require('./database')
|
||||
const PingController = require('./ping')
|
||||
const Server = require('./server')
|
||||
const { TimeTracker } = require('./time')
|
||||
const MessageOf = require('./message')
|
||||
const Database = require("./database");
|
||||
const PingController = require("./ping");
|
||||
const Server = require("./server");
|
||||
const { TimeTracker } = require("./time");
|
||||
const MessageOf = require("./message");
|
||||
|
||||
const config = require('../config')
|
||||
const minecraftVersions = require('../minecraft_versions')
|
||||
const config = require("../config");
|
||||
const minecraftVersions = require("../minecraft_versions");
|
||||
|
||||
class App {
|
||||
serverRegistrations = []
|
||||
serverRegistrations = [];
|
||||
|
||||
constructor () {
|
||||
this.pingController = new PingController(this)
|
||||
this.server = new Server(this)
|
||||
this.timeTracker = new TimeTracker(this)
|
||||
constructor() {
|
||||
this.pingController = new PingController(this);
|
||||
this.server = new Server(this);
|
||||
this.timeTracker = new TimeTracker(this);
|
||||
}
|
||||
|
||||
loadDatabase (callback) {
|
||||
this.database = new Database(this)
|
||||
loadDatabase(callback) {
|
||||
this.database = new Database(this);
|
||||
|
||||
// Setup database instance
|
||||
this.database.ensureIndexes(() => {
|
||||
this.database.loadGraphPoints(config.graphDuration, () => {
|
||||
this.database.loadRecords(() => {
|
||||
if (config.oldPingsCleanup && config.oldPingsCleanup.enabled) {
|
||||
this.database.initOldPingsDelete(callback)
|
||||
this.database.initOldPingsDelete(callback);
|
||||
} else {
|
||||
callback()
|
||||
callback();
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
handleReady () {
|
||||
this.server.listen(config.site.ip, config.site.port)
|
||||
handleReady() {
|
||||
this.server.listen(config.site.ip, config.site.port);
|
||||
|
||||
// Allow individual modules to manage their own task scheduling
|
||||
this.pingController.schedule()
|
||||
this.pingController.schedule();
|
||||
}
|
||||
|
||||
handleClientConnection = (client) => {
|
||||
if (config.logToDatabase) {
|
||||
client.on('message', (message) => {
|
||||
if (message === 'requestHistoryGraph') {
|
||||
client.on("message", (message) => {
|
||||
if (message === "requestHistoryGraph") {
|
||||
// Send historical graphData built from all serverRegistrations
|
||||
const graphData = this.serverRegistrations.map(serverRegistration => serverRegistration.graphData)
|
||||
const graphData = this.serverRegistrations.map(
|
||||
(serverRegistration) => serverRegistration.graphData
|
||||
);
|
||||
|
||||
// Send graphData in object wrapper to avoid needing to explicity filter
|
||||
// any header data being appended by #MessageOf since the graph data is fed
|
||||
// directly into the graphing system
|
||||
client.send(MessageOf('historyGraph', {
|
||||
timestamps: this.timeTracker.getGraphPoints(),
|
||||
graphData
|
||||
}))
|
||||
client.send(
|
||||
MessageOf("historyGraph", {
|
||||
timestamps: this.timeTracker.getGraphPoints(),
|
||||
graphData,
|
||||
})
|
||||
);
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
const initMessage = {
|
||||
config: (() => {
|
||||
// Remap minecraftVersion entries into name values
|
||||
const minecraftVersionNames = {}
|
||||
const minecraftVersionNames = {};
|
||||
Object.keys(minecraftVersions).forEach(function (key) {
|
||||
minecraftVersionNames[key] = minecraftVersions[key].map(version => version.name)
|
||||
})
|
||||
minecraftVersionNames[key] = minecraftVersions[key].map(
|
||||
(version) => version.name
|
||||
);
|
||||
});
|
||||
|
||||
// Send configuration data for rendering the page
|
||||
return {
|
||||
graphDurationLabel: config.graphDurationLabel || (Math.floor(config.graphDuration / (60 * 60 * 1000)) + 'h'),
|
||||
graphDurationLabel:
|
||||
config.graphDurationLabel ||
|
||||
Math.floor(config.graphDuration / (60 * 60 * 1000)) + "h",
|
||||
graphMaxLength: TimeTracker.getMaxGraphDataLength(),
|
||||
serverGraphMaxLength: TimeTracker.getMaxServerGraphDataLength(),
|
||||
servers: this.serverRegistrations.map(serverRegistration => serverRegistration.getPublicData()),
|
||||
servers: this.serverRegistrations.map((serverRegistration) =>
|
||||
serverRegistration.getPublicData()
|
||||
),
|
||||
minecraftVersions: minecraftVersionNames,
|
||||
isGraphVisible: config.logToDatabase
|
||||
}
|
||||
isGraphVisible: config.logToDatabase,
|
||||
};
|
||||
})(),
|
||||
timestampPoints: this.timeTracker.getServerGraphPoints(),
|
||||
servers: this.serverRegistrations.map(serverRegistration => serverRegistration.getPingHistory())
|
||||
}
|
||||
servers: this.serverRegistrations.map((serverRegistration) =>
|
||||
serverRegistration.getPingHistory()
|
||||
),
|
||||
};
|
||||
|
||||
client.send(MessageOf('init', initMessage))
|
||||
}
|
||||
client.send(MessageOf("init", initMessage));
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = App
|
||||
module.exports = App;
|
||||
|
Reference in New Issue
Block a user