fix issues reported by eslint
This commit is contained in:
parent
e9ab6fa400
commit
5ee39d77c0
|
|
@ -0,0 +1,19 @@
|
||||||
|
module.exports = {
|
||||||
|
"env": {
|
||||||
|
"commonjs": true,
|
||||||
|
"es6": true,
|
||||||
|
"node": true
|
||||||
|
},
|
||||||
|
"extends": "eslint:recommended",
|
||||||
|
"globals": {
|
||||||
|
"Atomics": "readonly",
|
||||||
|
"SharedArrayBuffer": "readonly"
|
||||||
|
},
|
||||||
|
"parserOptions": {
|
||||||
|
"ecmaVersion": 2018
|
||||||
|
},
|
||||||
|
"rules": {
|
||||||
|
"no-console": "off",
|
||||||
|
"semi": "warn",
|
||||||
|
}
|
||||||
|
};
|
||||||
56
index.js
56
index.js
|
|
@ -16,16 +16,6 @@ function monotonicTime() {
|
||||||
return mono;
|
return mono;
|
||||||
}
|
}
|
||||||
|
|
||||||
var appendJournal = (function() {
|
|
||||||
let lastJournalText = null;
|
|
||||||
return function appendJournal(text) {
|
|
||||||
if (text !== lastJournalText) {
|
|
||||||
fs.appendFileSync('journal/journal.txt', text + '\n');
|
|
||||||
lastJournalText = text;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
})();
|
|
||||||
|
|
||||||
function logDbError(label) {
|
function logDbError(label) {
|
||||||
return function(err) {
|
return function(err) {
|
||||||
console.error(label + ':', ((err && err.message) || err));
|
console.error(label + ':', ((err && err.message) || err));
|
||||||
|
|
@ -124,29 +114,7 @@ function waitForAnyGameUpdate() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function waitFor(duration) {
|
function waitFor(duration) {
|
||||||
return new Promise((resolve, reject) => setTimeout(() => { resolve(); }, duration));
|
return new Promise((resolve) => setTimeout(() => { resolve(); }, duration));
|
||||||
}
|
|
||||||
|
|
||||||
function checkString(value, label, dflt) {
|
|
||||||
try {
|
|
||||||
if (arguments.length >= 3 && (value === undefined || value === null)) {
|
|
||||||
return dflt;
|
|
||||||
} else if (typeof value === 'string') {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
} catch (err) {}
|
|
||||||
throw { message: `${label || 'value'} should be a string` };
|
|
||||||
}
|
|
||||||
|
|
||||||
function checkInteger(value, label, dflt) {
|
|
||||||
try {
|
|
||||||
if (arguments.length >= 3 && (value === undefined || value === null)) {
|
|
||||||
return dflt;
|
|
||||||
} else if (Number.isInteger(value)) {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
} catch(err) {}
|
|
||||||
throw { message: `${label || 'value'} should be an integer` };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function catchExceptionsJson(wrapped) {
|
function catchExceptionsJson(wrapped) {
|
||||||
|
|
@ -171,10 +139,10 @@ function catchExceptionsJson(wrapped) {
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
internalErrorJson(err);
|
internalErrorJson(err);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getGameListHandler(req, res, next) {
|
async function getGameListHandler(req, res) {
|
||||||
res.set('Cache-Control', 'no-store');
|
res.set('Cache-Control', 'no-store');
|
||||||
|
|
||||||
const afterTime =
|
const afterTime =
|
||||||
|
|
@ -191,7 +159,7 @@ async function getGameListHandler(req, res, next) {
|
||||||
|
|
||||||
const pollTimeout = waitFor(POLLING_TIMEOUT).then(() => 'timeout').catch(()=>{});
|
const pollTimeout = waitFor(POLLING_TIMEOUT).then(() => 'timeout').catch(()=>{});
|
||||||
|
|
||||||
while (true) {
|
for (;;) {
|
||||||
/* Save the async promise _before_ the query so we don't miss any updates while suspended. */
|
/* Save the async promise _before_ the query so we don't miss any updates while suspended. */
|
||||||
const gameUpdate = waitForAnyGameUpdate().then(() => 'update');
|
const gameUpdate = waitForAnyGameUpdate().then(() => 'update');
|
||||||
|
|
||||||
|
|
@ -226,7 +194,7 @@ async function getGameListHandler(req, res, next) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getGameHandler(req, res, next) {
|
async function getGameHandler(req, res) {
|
||||||
res.set('Cache-Control', 'no-store');
|
res.set('Cache-Control', 'no-store');
|
||||||
|
|
||||||
const gameId = req.params.gameId;
|
const gameId = req.params.gameId;
|
||||||
|
|
@ -248,7 +216,7 @@ async function getGameHandler(req, res, next) {
|
||||||
|
|
||||||
const pollTimeout = waitFor(POLLING_TIMEOUT).then(() => 'timeout').catch(()=>{});
|
const pollTimeout = waitFor(POLLING_TIMEOUT).then(() => 'timeout').catch(()=>{});
|
||||||
|
|
||||||
while (true) {
|
for (;;) {
|
||||||
/* Save the async promise _before_ the query so we don't miss any updates while suspended. */
|
/* Save the async promise _before_ the query so we don't miss any updates while suspended. */
|
||||||
const gameUpdate = waitForGameUpdate(gameId).then(() => 'update');
|
const gameUpdate = waitForGameUpdate(gameId).then(() => 'update');
|
||||||
|
|
||||||
|
|
@ -286,7 +254,7 @@ const updateTemplate = {
|
||||||
moves(x) { return Number.isInteger(x); },
|
moves(x) { return Number.isInteger(x); },
|
||||||
status(x) { return typeof x === 'string'; },
|
status(x) { return typeof x === 'string'; },
|
||||||
timestamp(x) { return Number.isInteger(x); },
|
timestamp(x) { return Number.isInteger(x); },
|
||||||
board(x) { return true; },
|
board(/*x*/) { return true; },
|
||||||
modified(x) { return Number.isInteger(x); },
|
modified(x) { return Number.isInteger(x); },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -311,7 +279,7 @@ function validateUpdate(body) {
|
||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function postGameHandler(req, res, next) {
|
async function postGameHandler(req, res) {
|
||||||
res.set('Cache-Control', 'no-store');
|
res.set('Cache-Control', 'no-store');
|
||||||
|
|
||||||
const gameId = req.params.gameId;
|
const gameId = req.params.gameId;
|
||||||
|
|
@ -344,8 +312,6 @@ async function postGameHandler(req, res, next) {
|
||||||
|
|
||||||
let setClause = '';
|
let setClause = '';
|
||||||
let whereClause = '';
|
let whereClause = '';
|
||||||
let hasBoard = false;
|
|
||||||
let hasMeta = false;
|
|
||||||
|
|
||||||
for (const key in body) {
|
for (const key in body) {
|
||||||
if (key !== 'modified') {
|
if (key !== 'modified') {
|
||||||
|
|
@ -354,10 +320,8 @@ async function postGameHandler(req, res, next) {
|
||||||
}
|
}
|
||||||
if (key === 'board') {
|
if (key === 'board') {
|
||||||
params['$' + key] = JSON.stringify(body[key]);
|
params['$' + key] = JSON.stringify(body[key]);
|
||||||
hasBoard = true;
|
|
||||||
} else {
|
} else {
|
||||||
params['$' + key] = body[key];
|
params['$' + key] = body[key];
|
||||||
hasMeta = true;
|
|
||||||
}
|
}
|
||||||
if (setClause !== '') {
|
if (setClause !== '') {
|
||||||
setClause += ', ';
|
setClause += ', ';
|
||||||
|
|
@ -381,7 +345,7 @@ async function postGameHandler(req, res, next) {
|
||||||
ON CONFLICT (gameId) DO UPDATE SET ${setClause}, modified = $time
|
ON CONFLICT (gameId) DO UPDATE SET ${setClause}, modified = $time
|
||||||
WHERE (${whereClause}) AND modified = $modified
|
WHERE (${whereClause}) AND modified = $modified
|
||||||
`;
|
`;
|
||||||
const selectSql = `SELECT * FROM games WHERE gameId = $gameId`
|
const selectSql = `SELECT * FROM games WHERE gameId = $gameId`;
|
||||||
let transactionP;
|
let transactionP;
|
||||||
db.serialize(() => {
|
db.serialize(() => {
|
||||||
/* Important: We need to start all these queries without waiting in between. */
|
/* Important: We need to start all these queries without waiting in between. */
|
||||||
|
|
@ -445,7 +409,7 @@ try {
|
||||||
maxAge: 0,
|
maxAge: 0,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
} catch (err) {}
|
} catch (err) {/*ignore*/}
|
||||||
|
|
||||||
var config = { port: process.env.OPENSHIFT_NODEJS_PORT || process.env.VCAP_APP_PORT || process.env.PORT || process.argv[2] || 8765 };
|
var config = { port: process.env.OPENSHIFT_NODEJS_PORT || process.env.VCAP_APP_PORT || process.env.PORT || process.argv[2] || 8765 };
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue