Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Nigel Complete Control committed Sep 12, 2018
2 parents 3eac6a9 + 9d8f7c2 commit fe09566
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 141 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ logs
*.log
npm-debug.log*

# Cached Files
/lib/*.dat

# Certificates
/certs

Expand Down
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: node bin/www
26 changes: 19 additions & 7 deletions lib/loadContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
var fs = require('fs'),
request = require('request'),
md5 = require('md5'),
debug = require('debug')('nasomi-auctionhouse-app:loadContent'),
promise = require('promise');

module.exports = function ( contentConfig ) {
Expand Down Expand Up @@ -73,8 +74,8 @@ module.exports = function ( contentConfig ) {
};

contentService.updateCachedCharacters = function ( responseObjectItemList ) {
if (responseObjectItemList.sale_list.length === 0) { return false; }
responseObjectItemList.sale_list.forEach(function ( objectItem, index ) {
if (responseObjectItemList.length === 0) { return false; }
responseObjectItemList.forEach(function ( objectItem, index ) {
contentService.cachedCharacters[objectItem.name] = {
id: objectItem.id,
updated: new Date().getTime()
Expand Down Expand Up @@ -126,10 +127,15 @@ module.exports = function ( contentConfig ) {
var cacheId = md5('searchCharByName'+charname);
var cachedObject = contentService.getCache( cacheId );
if (cachedObject === false) {
debug(options);
request(options, function (error, response, body) {
if (error) { reject(error); }
if (error) {
debug(error);
reject(error);
}
else {
var postDataReturned = JSON.parse(body);
debug(body);
contentService.setCache(cacheId, postDataReturned, 3600);
resolve(postDataReturned);
}
Expand Down Expand Up @@ -158,17 +164,23 @@ module.exports = function ( contentConfig ) {
var cacheId = md5('searchChar'+charid);
var cachedObject = contentService.getCache( cacheId );
if (cachedObject === false) {
debug(options);
request(options, function (error, response, body) {
if (error) { reject(error); }
if (error) {
debug(error);
reject(error);
}
else {
var postDataReturned = JSON.parse(body);
contentService.updatePopularCharacter( charid, postDataReturned[0].name );
debug(body);
contentService.updateCachedCharacters( postDataReturned );
// contentService.updatePopularCharacter( charid, postDataReturned[0].name );
contentService.setCache(cacheId, postDataReturned);
resolve(postDataReturned);
}
});
} else {
var postDataReturned = JSON.parse(cachedObject);
var postDataReturned = cachedObject;
contentService.updatePopularCharacter( charid, postDataReturned[0].name );
resolve(cachedObject);
}
Expand Down Expand Up @@ -229,7 +241,7 @@ module.exports = function ( contentConfig ) {
if (error) { reject(error); }
else {
var postDataReturned = JSON.parse(body);
contentService.updateCachedCharacters( postDataReturned );
contentService.updateCachedCharacters( postDataReturned.sale_list );
contentService.updatePopularItem( itemid, postDataReturned.sale_list[0].item_name );
contentService.setCache(cacheId, postDataReturned);
resolve(postDataReturned);
Expand Down
Loading

0 comments on commit fe09566

Please sign in to comment.