Apply code convention for passing linting
parent
e7df8a0c94
commit
140ba2f254
|
@ -26,9 +26,10 @@ const logger = require('debug')('middleware:filterware');
|
|||
|
||||
/**
|
||||
* private helper function to filter Objects by given keys
|
||||
* @param keys {Array} the keys from GET parameter filter
|
||||
* @param schema [Object} containing the keys as attributes that are allowed
|
||||
* @returns {Object or Error} either the filtered items or an Error object
|
||||
*
|
||||
* @param {Array} keys - the keys from GET parameter filter
|
||||
* @param {Object} schema - containing the keys as attributes that are allowed
|
||||
* @return {Object} either the filtered items or an Error object
|
||||
*/
|
||||
const limitFilterToSchema = (keys, schema) => {
|
||||
if (!keys || !schema) { // empty arrays evaluate to false
|
||||
|
@ -57,7 +58,7 @@ const limitFilterToSchema = (keys, schema) => {
|
|||
*/
|
||||
|
||||
const createFilterRouter = (schema, supressID) => {
|
||||
const router = express.Router();
|
||||
const router = new express.Router();
|
||||
// the exported router with handler
|
||||
router.use((req, res, next) => {
|
||||
const filterString = req.query.filter;
|
||||
|
|
|
@ -19,7 +19,8 @@
|
|||
// 3.) exports (which is module.exports)
|
||||
'use strict';
|
||||
|
||||
const router = require('express').Router();
|
||||
const express = require('express');
|
||||
const router = new express.Router();
|
||||
const logger = require('debug')('middleware:offsetlimit');
|
||||
|
||||
|
||||
|
|
|
@ -17,7 +17,8 @@
|
|||
// 3.) exports (which is module.exports)
|
||||
'use strict';
|
||||
|
||||
const router = require('express').Router();
|
||||
const express = require('express');
|
||||
const router = new express.Router();
|
||||
|
||||
// API-Version control. We use HTTP Header field Accept-Version instead of URL-part /v1/
|
||||
router.use((req, res, next) => {
|
||||
|
|
|
@ -5,6 +5,11 @@ const codes = require('../routes/http-codes');
|
|||
|
||||
/**
|
||||
* check if id has valid UUID format
|
||||
*
|
||||
* @param {object} req
|
||||
* @param {function} res
|
||||
* @param {function} next
|
||||
* @return {boolean}
|
||||
*/
|
||||
const idValidator = (req, res, next) => {
|
||||
const reqId = req.params.id;
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
// modules
|
||||
const express = require('express');
|
||||
const logger = require('debug')('cc:awardings');
|
||||
|
||||
// HTTP status codes by name
|
||||
const codes = require('./http-codes');
|
||||
|
@ -12,7 +11,7 @@ const routerHandling = require('../middleware/router-handling');
|
|||
// Mongoose Model using mongoDB
|
||||
const AppUserModel = require('../models/app-user');
|
||||
|
||||
const account = express.Router();
|
||||
const account = new express.Router();
|
||||
|
||||
account.route('/')
|
||||
.get((req, res, next) => {
|
||||
|
@ -35,7 +34,8 @@ account.route('/:id')
|
|||
.patch((req, res, next) => {
|
||||
if (!req.body || (req.body._id && req.body._id !== req.params.id)) {
|
||||
// little bit different as in PUT. :id does not need to be in data, but if the _id and url id must match
|
||||
const err = new Error('id of PATCH resource and send JSON body are not equal ' + req.params.id + ' ' + req.body._id);
|
||||
const err = new Error('id of PATCH resource and send JSON body are not equal ' + req.params.id + ' ' +
|
||||
req.body._id);
|
||||
err.status = codes.notfound;
|
||||
next(err);
|
||||
return; // prevent node to process this function further after next() has finished.
|
||||
|
|
|
@ -6,7 +6,6 @@ const jwt = require('jsonwebtoken');
|
|||
const bcrypt = require('bcryptjs');
|
||||
const Q = require('q');
|
||||
const _ = require('lodash');
|
||||
const logger = require('debug')('cc:authenticate');
|
||||
|
||||
// HTTP status codes by name
|
||||
const codes = require('./http-codes');
|
||||
|
@ -17,7 +16,7 @@ const routerHandling = require('../middleware/router-handling');
|
|||
|
||||
const AppUserModel = require('../models/app-user');
|
||||
|
||||
const authenticate = express.Router();
|
||||
const authenticate = new express.Router();
|
||||
|
||||
// routes **********************
|
||||
authenticate.route('/')
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
// modules
|
||||
const express = require('express');
|
||||
const logger = require('debug')('cc:awardings');
|
||||
|
||||
// HTTP status codes by name
|
||||
const codes = require('./http-codes');
|
||||
|
@ -20,7 +19,7 @@ const resultSet = {
|
|||
'__v': 0, 'updatedAt': 0, 'timestamp': 0, 'password': 0, 'permission': 0, 'secret': 0, 'activated': 0,
|
||||
};
|
||||
|
||||
const awarding = express.Router();
|
||||
const awarding = new express.Router();
|
||||
|
||||
|
||||
// routes **********************
|
||||
|
@ -100,7 +99,8 @@ awarding.route('/:id')
|
|||
.patch(apiAuthenticationMiddleware, checkHl, (req, res, next) => {
|
||||
if (!req.body || (req.body._id && req.body._id !== req.params.id)) {
|
||||
// little bit different as in PUT. :id does not need to be in data, but if the _id and url id must match
|
||||
const err = new Error('id of PATCH resource and send JSON body are not equal ' + req.params.id + ' ' + req.body._id);
|
||||
const err = new Error('id of PATCH resource and send JSON body are not equal ' + req.params.id + ' ' +
|
||||
req.body._id);
|
||||
err.status = codes.notfound;
|
||||
next(err);
|
||||
return; // prevent node to process this function further after next() has finished.
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
// modules
|
||||
const express = require('express');
|
||||
const logger = require('debug')('cc:campaigns');
|
||||
|
||||
// HTTP status codes by name
|
||||
const codes = require('./http-codes');
|
||||
|
@ -18,7 +17,7 @@ const CampaignModel = require('../models/campaign');
|
|||
const WarModel = require('../models/war');
|
||||
|
||||
|
||||
const campaigns = express.Router();
|
||||
const campaigns = new express.Router();
|
||||
|
||||
// routes **********************
|
||||
campaigns.route('/')
|
||||
|
|
|
@ -2,16 +2,12 @@
|
|||
|
||||
// modules
|
||||
const express = require('express');
|
||||
const logger = require('debug')('cc:command');
|
||||
|
||||
// HTTP status codes by name
|
||||
const codes = require('./http-codes');
|
||||
|
||||
const routerHandling = require('../middleware/router-handling');
|
||||
const createAllSignatures = require('../cron-job/cron').createAllSignatures;
|
||||
const createSignature = require('../tools/signature-tool');
|
||||
|
||||
const command = express.Router();
|
||||
const command = new express.Router();
|
||||
|
||||
command.route('/createSignature')
|
||||
.post((req, res, next) => {
|
||||
|
|
|
@ -6,7 +6,6 @@ const express = require('express');
|
|||
const multer = require('multer');
|
||||
const storage = multer.memoryStorage();
|
||||
const upload = multer({storage: storage});
|
||||
const logger = require('debug')('cc:decorations');
|
||||
|
||||
// HTTP status codes by name
|
||||
const codes = require('./http-codes');
|
||||
|
@ -21,8 +20,7 @@ const idValidator = require('../middleware/validators').idValidator;
|
|||
const DecorationModel = require('../models/decoration');
|
||||
const AwardingsModel = require('../models/awarding');
|
||||
|
||||
const decoration = express.Router();
|
||||
|
||||
const decoration = new express.Router();
|
||||
|
||||
// routes **********************
|
||||
decoration.route('/')
|
||||
|
@ -99,7 +97,8 @@ decoration.route('/:id')
|
|||
.patch(apiAuthenticationMiddleware, checkHl, upload.single('image'), (req, res, next) => {
|
||||
if (!req.body || (req.body._id && req.body._id !== req.params.id)) {
|
||||
// little bit different as in PUT. :id does not need to be in data, but if the _id and url id must match
|
||||
const err = new Error('id of PATCH resource and send JSON body are not equal ' + req.params.id + ' ' + req.body._id);
|
||||
const err = new Error('id of PATCH resource and send JSON body are not equal ' + req.params.id + ' ' +
|
||||
req.body._id);
|
||||
err.status = codes.notfound;
|
||||
next(err);
|
||||
return; // prevent node to process this function further after next() has finished.
|
||||
|
|
|
@ -3,10 +3,8 @@
|
|||
// modules
|
||||
const express = require('express');
|
||||
const async = require('async');
|
||||
const logger = require('debug')('cc:logs');
|
||||
|
||||
const routerHandling = require('../middleware/router-handling');
|
||||
const decimalToTimeString = require('../tools/util').decimalToTimeString;
|
||||
|
||||
// Mongoose Model using mongoDB
|
||||
const LogBudgetModel = require('../models/logs/budget');
|
||||
|
@ -18,9 +16,9 @@ const LogTransportModel = require('../models/logs/transport');
|
|||
const LogFlagModel = require('../models/logs/flag');
|
||||
const LogPointsModel = require('../models/logs/points');
|
||||
|
||||
const logsRouter = express.Router();
|
||||
const logsRouter = new express.Router();
|
||||
|
||||
function processLogRequest(model, filter, res, next) {
|
||||
const processLogRequest = (model, filter, res, next) => {
|
||||
model.find(filter, {}, {sort: {time: 1}}, (err, log) => {
|
||||
if (err) return next(err);
|
||||
if (!log || log.length === 0) {
|
||||
|
@ -31,7 +29,7 @@ function processLogRequest(model, filter, res, next) {
|
|||
res.locals.items = log;
|
||||
next();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// routes **********************
|
||||
logsRouter.route('/:warId')
|
||||
|
@ -58,7 +56,7 @@ logsRouter.route('/:warId')
|
|||
flag: flagObjects.exec.bind(flagObjects),
|
||||
};
|
||||
|
||||
async.parallel(resources, function(error, results) {
|
||||
async.parallel(resources, (error, results) => {
|
||||
if (error) {
|
||||
res.status(500).send(error);
|
||||
return;
|
||||
|
|
|
@ -3,10 +3,8 @@
|
|||
// modules
|
||||
const async = require('async');
|
||||
const express = require('express');
|
||||
const logger = require('debug')('cc:overview');
|
||||
|
||||
// HTTP status codes by name
|
||||
const codes = require('./http-codes');
|
||||
const routerHandling = require('../middleware/router-handling');
|
||||
|
||||
// Mongoose Model using mongoDB
|
||||
|
@ -14,7 +12,7 @@ const UserModel = require('../models/user');
|
|||
const SquadModel = require('../models/squad');
|
||||
const RankModel = require('../models/rank');
|
||||
|
||||
const overview = express.Router();
|
||||
const overview = new express.Router();
|
||||
|
||||
// routes **********************
|
||||
overview.route('/')
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
// modules
|
||||
const express = require('express');
|
||||
const logger = require('debug')('cc:players');
|
||||
|
||||
// HTTP status codes by name
|
||||
const codes = require('./http-codes');
|
||||
|
@ -17,7 +16,7 @@ const WarModel = require('../models/war');
|
|||
// Util
|
||||
const isSteamUUID = require('../tools/util').isSteamUUID;
|
||||
|
||||
const campaignPlayer = express.Router();
|
||||
const campaignPlayer = new express.Router();
|
||||
|
||||
// routes **********************
|
||||
campaignPlayer.route('/ranking/:campaignId')
|
||||
|
@ -67,7 +66,7 @@ campaignPlayer.route('/ranking/:campaignId')
|
|||
rankingItems.push(resItem);
|
||||
});
|
||||
|
||||
function getSortedField(fieldName) {
|
||||
const getSortedField = (fieldName) => {
|
||||
let num = 1;
|
||||
rankingItems.sort((a, b) => b[fieldName] - a[fieldName]);
|
||||
const res = JSON.parse(JSON.stringify(rankingItems));
|
||||
|
@ -75,7 +74,7 @@ campaignPlayer.route('/ranking/:campaignId')
|
|||
entity.num = num++;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
};
|
||||
|
||||
res.locals.items = {
|
||||
kill: getSortedField('kill'),
|
||||
|
|
|
@ -6,7 +6,6 @@ const express = require('express');
|
|||
const multer = require('multer');
|
||||
const storage = multer.memoryStorage();
|
||||
const upload = multer({storage: storage});
|
||||
const logger = require('debug')('cc:ranks');
|
||||
|
||||
// HTTP status codes by name
|
||||
const codes = require('./http-codes');
|
||||
|
@ -20,7 +19,7 @@ const idValidator = require('../middleware/validators').idValidator;
|
|||
// Mongoose Model using mongoDB
|
||||
const RankModel = require('../models/rank');
|
||||
|
||||
const ranks = express.Router();
|
||||
const ranks = new express.Router();
|
||||
|
||||
// routes **********************
|
||||
ranks.route('/')
|
||||
|
@ -91,7 +90,8 @@ ranks.route('/:id')
|
|||
.patch(apiAuthenticationMiddleware, checkHl, upload.single('image'), (req, res, next) => {
|
||||
if (!req.body || (req.body._id && req.body._id !== req.params.id)) {
|
||||
// little bit different as in PUT. :id does not need to be in data, but if the _id and url id must match
|
||||
const err = new Error('id of PATCH resource and send JSON body are not equal ' + req.params.id + ' ' + req.body._id);
|
||||
const err = new Error('id of PATCH resource and send JSON body are not equal ' + req.params.id + ' ' +
|
||||
req.body._id);
|
||||
err.status = codes.notfound;
|
||||
next(err);
|
||||
return; // prevent node to process this function further after next() has finished.
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
// modules
|
||||
const express = require('express');
|
||||
const logger = require('debug')('cc:awardings');
|
||||
|
||||
// HTTP status codes by name
|
||||
const codes = require('./http-codes');
|
||||
|
@ -29,7 +28,7 @@ const resultSet = {
|
|||
'activated': 0,
|
||||
};
|
||||
|
||||
const request = express.Router();
|
||||
const request = new express.Router();
|
||||
|
||||
|
||||
// routes **********************
|
||||
|
@ -131,7 +130,8 @@ request.route('/promotion/:id')
|
|||
.patch(apiAuthenticationMiddleware, checkHl, (req, res, next) => {
|
||||
if (!req.body || (req.body._id && req.body._id !== req.params.id)) {
|
||||
// little bit different as in PUT. :id does not need to be in data, but if the _id and url id must match
|
||||
const err = new Error('id of PATCH resource and send JSON body are not equal ' + req.params.id + ' ' + req.body._id);
|
||||
const err = new Error('id of PATCH resource and send JSON body are not equal ' + req.params.id + ' ' +
|
||||
req.body._id);
|
||||
err.status = codes.notfound;
|
||||
next(err);
|
||||
return; // prevent node to process this function further after next() has finished.
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
// modules
|
||||
const fs = require('fs');
|
||||
const express = require('express');
|
||||
const logger = require('debug')('cc:signatures');
|
||||
|
||||
// HTTP status codes by name
|
||||
const codes = require('./http-codes');
|
||||
|
@ -12,7 +11,7 @@ const routerHandling = require('../middleware/router-handling');
|
|||
|
||||
const UserModel = require('../models/user');
|
||||
|
||||
const signatures = express.Router();
|
||||
const signatures = new express.Router();
|
||||
|
||||
// routes **********************
|
||||
signatures.route('/:id')
|
||||
|
|
|
@ -6,7 +6,6 @@ const express = require('express');
|
|||
const multer = require('multer');
|
||||
const storage = multer.memoryStorage();
|
||||
const upload = multer({storage: storage});
|
||||
const logger = require('debug')('cc:squads');
|
||||
|
||||
// HTTP status codes by name
|
||||
const codes = require('./http-codes');
|
||||
|
@ -20,7 +19,7 @@ const idValidator = require('../middleware/validators').idValidator;
|
|||
// Mongoose Model using mongoDB
|
||||
const SquadModel = require('../models/squad');
|
||||
|
||||
const squads = express.Router();
|
||||
const squads = new express.Router();
|
||||
|
||||
// routes **********************
|
||||
squads.route('/')
|
||||
|
@ -94,7 +93,8 @@ squads.route('/:id')
|
|||
.patch(apiAuthenticationMiddleware, checkHl, upload.single('image'), (req, res, next) => {
|
||||
if (!req.body || (req.body._id && req.body._id !== req.params.id)) {
|
||||
// little bit different as in PUT. :id does not need to be in data, but if the _id and url id must match
|
||||
const err = new Error('id of PATCH resource and send JSON body are not equal ' + req.params.id + ' ' + req.body._id);
|
||||
const err = new Error('id of PATCH resource and send JSON body are not equal ' + req.params.id + ' ' +
|
||||
req.body._id);
|
||||
err.status = codes.notfound;
|
||||
next(err);
|
||||
return; // prevent node to process this function further after next() has finished.
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
// modules
|
||||
const express = require('express');
|
||||
const fs = require('fs');
|
||||
const logger = require('debug')('me2u5:users');
|
||||
|
||||
// HTTP status codes by name
|
||||
const codes = require('./http-codes');
|
||||
|
@ -21,7 +20,7 @@ const UserModel = require('../models/user');
|
|||
const SquadModel = require('../models/squad');
|
||||
const AwardingModel = require('../models/awarding');
|
||||
|
||||
const users = express.Router();
|
||||
const users = new express.Router();
|
||||
|
||||
users.get('/', filterHandlerCreator(UserModel.schema.paths));
|
||||
users.get('/', offsetlimitMiddleware);
|
||||
|
@ -107,7 +106,8 @@ users.route('/:id')
|
|||
.patch(apiAuthenticationMiddleware, checkHl, (req, res, next) => {
|
||||
if (!req.body || (req.body._id && req.body._id !== req.params.id)) {
|
||||
// little bit different as in PUT. :id does not need to be in data, but if the _id and url id must match
|
||||
const err = new Error('id of PATCH resource and send JSON body are not equal ' + req.params.id + ' ' + req.body._id);
|
||||
const err =
|
||||
new Error('id of PATCH resource and send JSON body are not equal ' + req.params.id + ' ' + req.body._id);
|
||||
err.status = codes.notfound;
|
||||
next(err);
|
||||
return; // prevent node to process this function further after next() has finished.
|
||||
|
@ -147,14 +147,15 @@ users.route('/:id')
|
|||
// first check that the given element id is the same as the URL id
|
||||
if (!req.body || req.body._id !== req.params.id) {
|
||||
// the URL does not fit the given element
|
||||
let err = new Error('id of PATCH resource and send JSON body are not equal ' + req.params.id + ' ' + req.body._id);
|
||||
let err =
|
||||
new Error('id of PATCH resource and send JSON body are not equal ' + req.params.id + ' ' + req.body._id);
|
||||
err.status = codes.notfound;
|
||||
next(err);
|
||||
return; // prevent node to process this function further after next() has finished.
|
||||
}
|
||||
// main difference of PUT and PATCH is that PUT expects all data in request: checked by using the schema
|
||||
const user = new UserModel(req.body);
|
||||
UserModel.findById(req.params.id, req.body, {new: true}, function(err, item) {
|
||||
UserModel.findById(req.params.id, req.body, {new: true}, (err, item) => {
|
||||
// with parameter {new: true} the TweetNModel will return the new and changed object from the DB and not the
|
||||
// old one.
|
||||
if (err) {
|
||||
|
@ -164,9 +165,8 @@ users.route('/:id')
|
|||
err = new Error('item not found');
|
||||
err.status = codes.notfound;
|
||||
return next(err);
|
||||
}
|
||||
// check that version is still accurate
|
||||
else if (user.__v !== item.__v) {
|
||||
} else if (user.__v !== item.__v) {
|
||||
// checked that version is still accurate
|
||||
err = new Error('version outdated. Meanwhile update on item happened. Please GET resource again');
|
||||
err.status = codes.conflict;
|
||||
return next(err);
|
||||
|
@ -182,7 +182,7 @@ users.route('/:id')
|
|||
// update updatedAt and increase version
|
||||
item.updatedAt = new Date();
|
||||
item.increment(); // this sets __v++
|
||||
item.save(function(err) {
|
||||
item.save((err) => {
|
||||
if (!err) {
|
||||
res.locals.items = item;
|
||||
} else {
|
||||
|
|
|
@ -7,7 +7,6 @@ const express = require('express');
|
|||
const multer = require('multer');
|
||||
const storage = multer.memoryStorage();
|
||||
const upload = multer({storage: storage});
|
||||
const logger = require('debug')('cc:wars');
|
||||
|
||||
// HTTP status codes by name
|
||||
const codes = require('./http-codes');
|
||||
|
@ -35,7 +34,7 @@ const LogFlagModel = require('../models/logs/flag');
|
|||
const LogBudgetModel = require('../models/logs/budget');
|
||||
const LogPointsModel = require('../models/logs/points');
|
||||
|
||||
const wars = express.Router();
|
||||
const wars = new express.Router();
|
||||
|
||||
// routes **********************
|
||||
wars.route('/')
|
||||
|
@ -88,20 +87,20 @@ wars.route('/')
|
|||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
PlayerModel.create(statsResult.players, function(err) {
|
||||
PlayerModel.create(statsResult.players, (err) => {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
LogKillModel.create(statsResult.kills, function() {
|
||||
LogVehicleKillModel.create(statsResult.vehicles, function() {
|
||||
LogRespawnModel.create(statsResult.respawn, function() {
|
||||
LogReviveModel.create(statsResult.revive, function() {
|
||||
LogFlagModel.create(statsResult.flag, function() {
|
||||
LogBudgetModel.create(statsResult.budget, function() {
|
||||
LogTransportModel.create(statsResult.transport, function() {
|
||||
LogPointsModel.create(statsResult.points, function() {
|
||||
LogKillModel.create(statsResult.kills, () => {
|
||||
LogVehicleKillModel.create(statsResult.vehicles, () => {
|
||||
LogRespawnModel.create(statsResult.respawn, () => {
|
||||
LogReviveModel.create(statsResult.revive, () => {
|
||||
LogFlagModel.create(statsResult.flag, () => {
|
||||
LogBudgetModel.create(statsResult.budget, () => {
|
||||
LogTransportModel.create(statsResult.transport, () => {
|
||||
LogPointsModel.create(statsResult.points, () => {
|
||||
const folderName = __dirname + '/../resource/logs/' + war._id;
|
||||
mkdirp(folderName, function(err) {
|
||||
mkdirp(folderName, (err) => {
|
||||
if (err) return next(err);
|
||||
|
||||
// save clean log file
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
let mongoose = require('mongoose');
|
||||
let AwardingModel = require('../models/awarding');
|
||||
let urls = require('../config/api-url');
|
||||
let codes = require('../routes/http-codes');
|
||||
|
@ -8,7 +7,6 @@ let codes = require('../routes/http-codes');
|
|||
let chai = require('chai');
|
||||
let chaiHttp = require('chai-http');
|
||||
let server = require('../server');
|
||||
let should = chai.should();
|
||||
|
||||
chai.use(chaiHttp);
|
||||
// Our parent block
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
let mongoose = require('mongoose');
|
||||
let AwardingModel = require('../models/awarding');
|
||||
let urls = require('../config/api-url');
|
||||
let codes = require('../routes/http-codes');
|
||||
|
@ -8,7 +7,6 @@ let codes = require('../routes/http-codes');
|
|||
let chai = require('chai');
|
||||
let chaiHttp = require('chai-http');
|
||||
let server = require('../server');
|
||||
let should = chai.should();
|
||||
|
||||
chai.use(chaiHttp);
|
||||
// Our parent block
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
let mongoose = require('mongoose');
|
||||
let DecorationModel = require('../models/decoration');
|
||||
let urls = require('../config/api-url');
|
||||
let codes = require('../routes/http-codes');
|
||||
|
@ -8,7 +7,6 @@ let codes = require('../routes/http-codes');
|
|||
let chai = require('chai');
|
||||
let chaiHttp = require('chai-http');
|
||||
let server = require('../server');
|
||||
let should = chai.should();
|
||||
|
||||
chai.use(chaiHttp);
|
||||
// Our parent block
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
let mongoose = require('mongoose');
|
||||
let RankModel = require('../models/rank');
|
||||
let urls = require('../config/api-url');
|
||||
let codes = require('../routes/http-codes');
|
||||
|
@ -8,7 +7,6 @@ let codes = require('../routes/http-codes');
|
|||
let chai = require('chai');
|
||||
let chaiHttp = require('chai-http');
|
||||
let server = require('../server');
|
||||
let should = chai.should();
|
||||
|
||||
chai.use(chaiHttp);
|
||||
// Our parent block
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
let mongoose = require('mongoose');
|
||||
let SquadModel = require('../models/squad');
|
||||
let urls = require('../config/api-url');
|
||||
let codes = require('../routes/http-codes');
|
||||
|
@ -8,7 +7,6 @@ let codes = require('../routes/http-codes');
|
|||
let chai = require('chai');
|
||||
let chaiHttp = require('chai-http');
|
||||
let server = require('../server');
|
||||
let should = chai.should();
|
||||
|
||||
chai.use(chaiHttp);
|
||||
// Our parent block
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
let mongoose = require('mongoose');
|
||||
let UserModel = require('../models/user');
|
||||
let AppUserModel = require('../models/app-user');
|
||||
let urls = require('../config/api-url');
|
||||
let codes = require('../routes/http-codes');
|
||||
|
||||
|
@ -9,7 +7,6 @@ let codes = require('../routes/http-codes');
|
|||
let chai = require('chai');
|
||||
let chaiHttp = require('chai-http');
|
||||
let server = require('../server');
|
||||
let should = chai.should();
|
||||
|
||||
chai.use(chaiHttp);
|
||||
// Our parent block
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
let mongoose = require('mongoose');
|
||||
let AwardingModel = require('../models/awarding');
|
||||
let urls = require('../config/api-url');
|
||||
let codes = require('../routes/http-codes');
|
||||
|
||||
|
@ -8,7 +6,6 @@ let codes = require('../routes/http-codes');
|
|||
let chai = require('chai');
|
||||
let chaiHttp = require('chai-http');
|
||||
let server = require('../server');
|
||||
let should = chai.should();
|
||||
|
||||
chai.use(chaiHttp);
|
||||
// Our parent block
|
||||
|
|
|
@ -48,10 +48,10 @@ const parseWarLog = (lineArray, war) => {
|
|||
line = line.substring(line.indexOf(NAME_TOO_LONG_ERROR) + NAME_TOO_LONG_ERROR.length);
|
||||
}
|
||||
|
||||
if (line.includes('(Abschuss)')) {
|
||||
/**
|
||||
* KILLS & VEHICLE KILLS
|
||||
*/
|
||||
if (line.includes('(Abschuss)')) {
|
||||
stats.clean.push(line);
|
||||
|
||||
const shooterString = line.substring(line.lastIndexOf(' von: ') + 6, line.lastIndexOf('."'));
|
||||
|
@ -81,12 +81,10 @@ const parseWarLog = (lineArray, war) => {
|
|||
fraction: shooter ? shooter.fraction : 'NONE',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
} else if (line.includes('(Budget)')) {
|
||||
/**
|
||||
* BUDGET
|
||||
*/
|
||||
else if (line.includes('(Budget)')) {
|
||||
stats.clean.push(line);
|
||||
const budg = line.split(WHITESPACE);
|
||||
if (line.includes('Startbudget')) {
|
||||
|
@ -103,12 +101,10 @@ const parseWarLog = (lineArray, war) => {
|
|||
} else {
|
||||
stats.budget.push(getBudgetEntry(budg, war._id, war.date));
|
||||
}
|
||||
}
|
||||
|
||||
} else if (line.includes('(Fahne)') && !line.includes('Dominator')) {
|
||||
/**
|
||||
* FLAG
|
||||
*/
|
||||
else if (line.includes('(Fahne)') && !line.includes('Dominator')) {
|
||||
stats.clean.push(line);
|
||||
const playerName = line.substring(line.lastIndexOf('rt von ') + 7).slice(0, -2);
|
||||
const flagFraction = line.includes('NATO Flagge') ? 'BLUFOR' : 'OPFOR';
|
||||
|
@ -121,12 +117,10 @@ const parseWarLog = (lineArray, war) => {
|
|||
flagFraction: flagFraction,
|
||||
capture: capture,
|
||||
});
|
||||
}
|
||||
|
||||
} else if (line.includes('(Punkte)')) {
|
||||
/**
|
||||
* POINTS
|
||||
*/
|
||||
else if (line.includes('(Punkte)')) {
|
||||
stats.clean.push(line);
|
||||
const pt = line.split(WHITESPACE);
|
||||
|
||||
|
@ -138,21 +132,17 @@ const parseWarLog = (lineArray, war) => {
|
|||
} else {
|
||||
stats.points.push(getPointsEntry(pt, line, war._id, war.date));
|
||||
}
|
||||
}
|
||||
|
||||
} else if (line.includes('(Respawn)')) {
|
||||
/**
|
||||
* RESPAWN
|
||||
*/
|
||||
else if (line.includes('(Respawn)')) {
|
||||
const resp = line.split(WHITESPACE);
|
||||
const playerName = line.substring(line.lastIndexOf('Spieler:') + 9, line.lastIndexOf('- Kosten') - 1);
|
||||
stats.respawn.push(getRespawnEntry(resp, playerName, war._id, war.date));
|
||||
}
|
||||
|
||||
} else if (line.includes('(Revive)')) {
|
||||
/**
|
||||
* REVIVE
|
||||
*/
|
||||
else if (line.includes('(Revive)')) {
|
||||
stats.clean.push(line);
|
||||
const stabilized = !!line.includes('stabilisiert."');
|
||||
const medicName = line.substring(line.lastIndexOf('wurde von ') + 10,
|
||||
|
@ -169,12 +159,10 @@ const parseWarLog = (lineArray, war) => {
|
|||
patient: patient.name,
|
||||
fraction: medic.fraction,
|
||||
});
|
||||
}
|
||||
|
||||
} else if (line.includes('(Transport)')) {
|
||||
/**
|
||||
* TRANSPORT
|
||||
*/
|
||||
else if (line.includes('(Transport)')) {
|
||||
stats.clean.push(line);
|
||||
const driverString = line.substring(line.lastIndexOf('wurde von ') + 10, line.lastIndexOf(' eingeflogen'));
|
||||
const driver = getPlayerAndFractionFromString(driverString);
|
||||
|
@ -190,12 +178,10 @@ const parseWarLog = (lineArray, war) => {
|
|||
fraction: driver ? driver.fraction : 'NONE',
|
||||
distance: distance,
|
||||
});
|
||||
}
|
||||
|
||||
} else if (line.includes('(Fraktionsuebersicht)')) {
|
||||
/**
|
||||
* PLAYERS
|
||||
*/
|
||||
else if (line.includes('(Fraktionsuebersicht)')) {
|
||||
const playerString = line.substring(line.lastIndexOf('--- ') + 4, line.lastIndexOf(', PUID'));
|
||||
const playerUUID = line.substring(line.lastIndexOf('PUID ') + 5, line.lastIndexOf('"'));
|
||||
addPlayerIfNotExists(playerString, playerUUID);
|
||||
|
@ -253,7 +239,10 @@ const getBudgetEntry = (budg, warId, warDate) => {
|
|||
|
||||
const getPlayerAndFractionFromString = (nameAndFractionString) => {
|
||||
const nameArray = nameAndFractionString.split(WHITESPACE);
|
||||
const fraction = nameArray[nameArray.length - 1] !== '(ENEMY)' ? nameArray[nameArray.length - 1] === '(WEST)' ? 'BLUFOR' : 'OPFOR' : undefined;
|
||||
const fraction = nameArray[nameArray.length - 1] !== '(ENEMY)' ?
|
||||
nameArray[nameArray.length - 1] === '(WEST)' ?
|
||||
'BLUFOR' : 'OPFOR' :
|
||||
undefined;
|
||||
const name = nameAndFractionString.substring(0, nameAndFractionString.indexOf(nameArray[nameArray.length - 1]) - 1);
|
||||
// do not return player for 'Selbstverschulden' or 'Error: No unit'
|
||||
if (name && name !== 'Error: No unit') {
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
const jimp = require('jimp');
|
||||
const imagemin = require('imagemin');
|
||||
const imageminpngquant = require('imagemin-pngquant');
|
||||
const SHA1 = require('node-sha1');
|
||||
const sha1 = require('node-sha1');
|
||||
const async = require('async');
|
||||
|
||||
// Mongoose Model using mongoDB
|
||||
|
@ -63,7 +63,10 @@ let createSignature = (userId, res, next) => {
|
|||
return font;
|
||||
})
|
||||
.then((font) => {
|
||||
let rankH, rankW, rankX, rankY;
|
||||
let rankH;
|
||||
let rankW;
|
||||
let rankX;
|
||||
let rankY;
|
||||
|
||||
RankModel.findOne({'level': user.rankLvl, 'fraction': user.squadId.fraction}, (err, result) => {
|
||||
if (err) {
|
||||
|
@ -110,10 +113,10 @@ let createSignature = (userId, res, next) => {
|
|||
* query decorations according to user id and
|
||||
* add all graphics into given image
|
||||
*
|
||||
* @param userId
|
||||
* @param loadedImage - background image
|
||||
* @param res
|
||||
* @param next
|
||||
* @param {number} userId
|
||||
* @param {Object} loadedImage - background image
|
||||
* @param {function} res
|
||||
* @param {function} next
|
||||
*/
|
||||
let addDecorationsAndSave = (userId, loadedImage, res, next) => {
|
||||
const medalW = 21;
|
||||
|
@ -220,8 +223,8 @@ let compareImagesAndSave = (generatedImage, userId, res, next) => {
|
|||
return jimp.read(resourceDir + 'signature/big/' + userId + fileExt)
|
||||
.then((oldImage) => {
|
||||
// compare hashes of image map to recognize difference
|
||||
const sig1 = SHA1(generatedImage.bitmap.data);
|
||||
const sig2 = SHA1(oldImage.bitmap.data);
|
||||
const sig1 = sha1(generatedImage.bitmap.data);
|
||||
const sig2 = sha1(oldImage.bitmap.data);
|
||||
if (sig1 !== sig2) {
|
||||
saveJimpImageAndCompress(generatedImage, userId, res, next);
|
||||
} else {
|
||||
|
@ -235,14 +238,13 @@ let compareImagesAndSave = (generatedImage, userId, res, next) => {
|
|||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* Write Jimp image to file system
|
||||
* Gets minified after 3 seconds timeout
|
||||
*
|
||||
* @param image - Jimp image
|
||||
* @param userId - user id of signature owner
|
||||
* @param res - express response object
|
||||
* @param next - express next-function
|
||||
* @param {Object} image - Jimp image
|
||||
* @param {number} userId - user id of signature owner
|
||||
* @param {function} res - express response object
|
||||
* @param {function} next - express next-function
|
||||
*/
|
||||
let saveJimpImageAndCompress = (image, userId, res, next) => {
|
||||
image.write(resourceDir + 'signature/big/' + userId + fileExt);
|
||||
|
|
Loading…
Reference in New Issue