extrapolated postToStats() in serveController.js

This commit is contained in:
bill bittner 2017-09-07 11:46:06 -07:00
parent 69741dfc1d
commit c901ced94c
2 changed files with 4 additions and 5 deletions

View file

@ -166,16 +166,16 @@ module.exports = {
} else { } else {
fileInfo['fileExt'] = fileInfo.fileName.substring(fileInfo.fileName.lastIndexOf('.') + 1); fileInfo['fileExt'] = fileInfo.fileName.substring(fileInfo.fileName.lastIndexOf('.') + 1);
} }
// add stats table
postToStats(method, originalUrl, ip, fileInfo.name, fileInfo.claimId, 'success');
// serve or show // serve or show
switch (method) { switch (method) {
case SERVE: case SERVE:
serveFile(fileInfo, res); serveFile(fileInfo, res);
sendGoogleAnalytics(method, headers, ip, originalUrl); sendGoogleAnalytics(method, headers, ip, originalUrl);
postToStats('serve', originalUrl, ip, fileInfo.name, fileInfo.claimId, 'success');
return fileInfo; return fileInfo;
case SHOWLITE: case SHOWLITE:
showFileLite(fileInfo, res); showFileLite(fileInfo, res);
postToStats('show', originalUrl, ip, fileInfo.name, fileInfo.claimId, 'success');
return fileInfo; return fileInfo;
case SHOW: case SHOW:
return getShortClaimIdFromLongClaimId(fileInfo.claimId, fileInfo.name) return getShortClaimIdFromLongClaimId(fileInfo.claimId, fileInfo.name)
@ -184,15 +184,13 @@ module.exports = {
return resolveAgainstClaimTable(fileInfo.name, fileInfo.claimId); return resolveAgainstClaimTable(fileInfo.name, fileInfo.claimId);
}) })
.then(resolveResult => { .then(resolveResult => {
logger.debug('resolve result', resolveResult);
fileInfo['title'] = resolveResult.title; fileInfo['title'] = resolveResult.title;
fileInfo['description'] = resolveResult.description; fileInfo['description'] = resolveResult.description;
showFile(fileInfo, res); showFile(fileInfo, res);
postToStats('show', originalUrl, ip, fileInfo.name, fileInfo.claimId, 'success');
return fileInfo; return fileInfo;
}) })
.catch(error => { .catch(error => {
console.log('thowing error...'); logger.error('throwing serve/show error...');
throw error; throw error;
}); });
default: default:

View file

@ -6,6 +6,7 @@ const googleApiKey = config.get('AnalyticsConfig.GoogleId');
module.exports = { module.exports = {
postToStats (action, url, ipAddress, name, claimId, result) { postToStats (action, url, ipAddress, name, claimId, result) {
logger.debug('action:', action);
// make sure the result is a string // make sure the result is a string
if (result && (typeof result !== 'string')) { if (result && (typeof result !== 'string')) {
result = result.toString(); result = result.toString();