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

View file

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