From bc4293da03b93900874bfbe9136f38e49579fec2 Mon Sep 17 00:00:00 2001 From: "Ronald M. Clifford" Date: Mon, 7 Jan 2019 23:44:47 -0800 Subject: [PATCH] Fix bugs with GitHub, Blogger, Blizzard, and more. --- roncli.com/app/controllers/home_controller.js | 2 +- roncli.com/app/templates/home/index.hbs | 14 +-- roncli.com/assets/css/site.css | 6 +- roncli.com/package.json | 4 +- roncli.com/server/github/github.js | 98 ++++++++----------- roncli.com/server/models/blog.js | 14 +-- roncli.com/server/models/coding.js | 2 +- roncli.com/server/models/gaming.js | 12 +-- roncli.com/server/models/music.js | 14 +-- 9 files changed, 78 insertions(+), 88 deletions(-) diff --git a/roncli.com/app/controllers/home_controller.js b/roncli.com/app/controllers/home_controller.js index 679799bc..b57147ef 100644 --- a/roncli.com/app/controllers/home_controller.js +++ b/roncli.com/app/controllers/home_controller.js @@ -23,7 +23,7 @@ module.exports = { life: {collection: "LifeFeatures", params: {}} }, function(err, result) { if (!err && result && result.blog && result.blog.models && result.blog.models[0] && result.blog.models[0].attributes && result.blog.models[0].attributes.error) { - err = result.blog.models[0].attributes; + result.blogMissing = true; } if (!err && result && result.songs && result.songs.models && result.songs.models[0] && result.songs.models[0].attributes && result.songs.models[0].attributes.error) { diff --git a/roncli.com/app/templates/home/index.hbs b/roncli.com/app/templates/home/index.hbs index c2746867..ef4af6d5 100644 --- a/roncli.com/app/templates/home/index.hbs +++ b/roncli.com/app/templates/home/index.hbs @@ -1,10 +1,12 @@
-
- -

Latest Blog Post

-
- {{partial "blog/post" post=blog.models.0.attributes.post header="default"}} -
+ {{#unless blogMissing}} +
+ +

Latest Blog Post

+
+ {{partial "blog/post" post=blog.models.0.attributes.post header="default"}} +
+ {{/unless}}
diff --git a/roncli.com/assets/css/site.css b/roncli.com/assets/css/site.css index 551d6c77..aa6dd4ef 100644 --- a/roncli.com/assets/css/site.css +++ b/roncli.com/assets/css/site.css @@ -692,4 +692,8 @@ pre.code.inline { div.blog span.media { font-weight: bold; color: #808080; -} \ No newline at end of file +} + +label.error { + display: block; +} diff --git a/roncli.com/package.json b/roncli.com/package.json index 744f5206..7f5627aa 100644 --- a/roncli.com/package.json +++ b/roncli.com/package.json @@ -18,7 +18,7 @@ "url": "https://github.com/roncli/roncli.com.git" }, "dependencies": { - "blizzhub": "1.0.14", + "blizzhub": "1.0.15", "body-parser": "1.18.3", "captchagen": "1.2.0", "compression": "1.7.3", @@ -48,7 +48,7 @@ "tumblr": "0.4.1", "twitter": "1.7.1", "underscore": "1.9.1", - "@octokit/rest": "16.3.2" + "@octokit/rest": "16.6.0" }, "devDependencies": { "grunt": "1.0.3", diff --git a/roncli.com/server/github/github.js b/roncli.com/server/github/github.js index 892453df..56b177ab 100644 --- a/roncli.com/server/github/github.js +++ b/roncli.com/server/github/github.js @@ -23,28 +23,12 @@ var config = require("../privateConfig").github, /** * Gets the events from GitHub. - * @param {object} [link] The link object to determine the page to retrieve. If not passed, gets the first page. */ - getEvents = function(link) { - var processEvents = function(err, events) { + getEvents = function() { + var processEvents = function(events) { var releaseEvents, pushEvents, allEvents; - if (err) { - console.log("Bad response from GitHub while getting events."); - console.log(err); - callback({ - error: "Bad response from GitHub.", - status: 502 - }); - return; - } - - totalEvents = [].concat.apply([], [totalEvents, events.data]); - - if (client.hasNextPage(events)) { - getEvents(events); - return; - } + totalEvents = [].concat.apply([], [totalEvents, events]); releaseEvents = totalEvents.filter(function(event) { return event.type === "ReleaseEvent" && event.payload.action === "published" && !event.payload.release.draft; @@ -95,11 +79,17 @@ var config = require("../privateConfig").github, }); }; - if (link) { - client.getNextPage(link, processEvents); - } else { - client.activity.getEventsForUser({username: "roncli", per_page: 100}, processEvents); - } + var options = client.activity.listEventsForUser.endpoint.merge({username: "roncli", per_page: 100}); + + client.paginate(options).then(processEvents).catch(function(err) { + console.log("Bad response from GitHub while listing events for user."); + console.log(err); + callback({ + error: "Bad response from GitHub.", + status: 502 + }); + return; + }); }; getEvents(); @@ -118,17 +108,7 @@ var config = require("../privateConfig").github, commitsDeferred = new Deferred(), releasesDeferred = new Deferred(); - client.repos.get({owner: user, repo: repository}, function(err, repo) { - if (err) { - console.log("Bad response from GitHub while getting a repository."); - console.log(err); - repositoryDeferred.reject({ - error: "Bad response from GitHub.", - status: 502 - }); - return; - } - + client.repos.get({owner: user, repo: repository}).then(function(repo) { repositoryDeferred.resolve({ user: repo.data.owner.login, repository: repo.data.name, @@ -139,19 +119,17 @@ var config = require("../privateConfig").github, gitUrl: repo.data.git_url, language: repo.data.language }); + }).catch(function(err) { + console.log("Bad response from GitHub while getting a repository."); + console.log(err); + repositoryDeferred.reject({ + error: "Bad response from GitHub.", + status: 502 + }); + return; }); - client.repos.getCommits({owner: user, repo: repository, per_page: 100}, function(err, commits) { - if (err) { - console.log("Bad response from GitHub while getting commits for a repository."); - console.log(err); - commitsDeferred.reject({ - error: "Bad response from GitHub.", - status: 502 - }); - return; - } - + client.repos.listCommits({owner: user, repo: repository, per_page: 100}).then(function(commits) { commitsDeferred.resolve(commits.data.map(function(commit) { var date = new Date(commit.commit.author.date).getTime(); return { @@ -165,19 +143,17 @@ var config = require("../privateConfig").github, } }; })); + }).catch(function(err) { + console.log("Bad response from GitHub while getting commits for a repository."); + console.log(err); + commitsDeferred.reject({ + error: "Bad response from GitHub.", + status: 502 + }); + return; }); - client.repos.getReleases({owner: user, repo: repository, per_page: 100}, function(err, releases) { - if (err) { - console.log("Bad response from GitHub while getting releases for a repository."); - console.log(err); - releasesDeferred.reject({ - error: "Bad response from GitHub.", - status: 502 - }); - return; - } - + client.repos.listReleases({owner: user, repo: repository, per_page: 100}).then(function(releases) { releasesDeferred.resolve(releases.data.filter(function(release) { return !release.draft; }).map(function(release) { @@ -194,6 +170,14 @@ var config = require("../privateConfig").github, } }; })); + }).catch(function(err) { + console.log("Bad response from GitHub while getting releases for a repository."); + console.log(err); + releasesDeferred.reject({ + error: "Bad response from GitHub.", + status: 502 + }); + return; }); all([repositoryDeferred.promise, commitsDeferred.promise, releasesDeferred.promise]).then( diff --git a/roncli.com/server/models/blog.js b/roncli.com/server/models/blog.js index ab755b67..c2d29c25 100644 --- a/roncli.com/server/models/blog.js +++ b/roncli.com/server/models/blog.js @@ -195,7 +195,7 @@ module.exports.getLatestPostByCategory = function(category, callback) { }; getPost(function() { - cachePosts(false, function(err) { + cachePosts(true, function(err) { if (err) { callback(err); return; @@ -237,7 +237,7 @@ module.exports.getPostByIndex = function(index, callback) { }; getPost(function() { - cachePosts(false, function(err) { + cachePosts(true, function(err) { if (err) { callback(err); return; @@ -279,7 +279,7 @@ module.exports.getPostByUrl = function(url, callback) { }; getPostFromUrl(url, getPost, function() { - cachePosts(false, function(err) { + cachePosts(true, function(err) { if (err) { callback(err); return; @@ -386,7 +386,7 @@ module.exports.getPost = function(post, callback) { } getIndex("roncli.com:blog:posts", rankDeferred, function() { - cachePosts(false, function(err) { + cachePosts(true, function(err) { if (err) { rankDeferred.reject(err); return; @@ -530,7 +530,7 @@ module.exports.getCategories = function(callback) { }; getCategories(function() { - cachePosts(false, function(err) { + cachePosts(true, function(err) { if (err) { callback(err); return; @@ -632,7 +632,7 @@ module.exports.getCommentsByUrl = function(url, callback) { }; getPostFromUrl(url, getComments, function() { - cachePosts(false, function(err) { + cachePosts(true, function(err) { if (err) { callback(err); return; @@ -704,7 +704,7 @@ module.exports.postComment = function(userId, url, content, callback) { }; getPostFromUrl(url, resolve, function() { - cachePosts(false, function(err) { + cachePosts(true, function(err) { if (err) { callback(err); return; diff --git a/roncli.com/server/models/coding.js b/roncli.com/server/models/coding.js index 0046ddae..1970f425 100644 --- a/roncli.com/server/models/coding.js +++ b/roncli.com/server/models/coding.js @@ -67,7 +67,7 @@ module.exports.getLatestEvents = function(count, callback) { }; getEvents(function() { - github.cacheEvents(false, function(err) { + github.cacheEvents(true, function(err) { if (err) { callback(err); return; diff --git a/roncli.com/server/models/gaming.js b/roncli.com/server/models/gaming.js index 948d78d4..803a9e0d 100644 --- a/roncli.com/server/models/gaming.js +++ b/roncli.com/server/models/gaming.js @@ -201,7 +201,7 @@ module.exports.getWowFeed = function(callback) { }; getWowCharacter(getFeed, function() { - wow.cacheCharacter(false, function(err) { + wow.cacheCharacter(true, function(err) { if (err) { callback(err); return; @@ -278,7 +278,7 @@ module.exports.getLatestWowFeed = function(callback) { }; getWowCharacter(getFeed, function() { - wow.cacheCharacter(false, function(err) { + wow.cacheCharacter(true, function(err) { if (err) { callback(err); return; @@ -338,7 +338,7 @@ module.exports.getDiabloHeroes = function(callback) { }; getHeroes(function() { - d3.cacheProfile(false, function(err) { + d3.cacheProfile(true, function(err) { if (err) { callback(err); return; @@ -388,7 +388,7 @@ module.exports.getDiabloMain = function(callback) { }; getProfile(function() { - d3.cacheProfile(false, function(err) { + d3.cacheProfile(true, function(err) { if (err) { callback(err); return; @@ -434,7 +434,7 @@ module.exports.getSteamGames = function(callback) { }; getGames(function() { - steam.cacheGames(false, function(err) { + steam.cacheGames(true, function(err) { if (err) { callback(err); return; @@ -566,7 +566,7 @@ module.exports.getDclPilot = function(latest, callback) { }; getPilot(function() { - dcl.cachePilot(false, function(err) { + dcl.cachePilot(true, function(err) { if (err) { callback(err); return; diff --git a/roncli.com/server/models/music.js b/roncli.com/server/models/music.js index b5463397..f58cc8b4 100644 --- a/roncli.com/server/models/music.js +++ b/roncli.com/server/models/music.js @@ -60,7 +60,7 @@ module.exports.getLatestSongs = function(count, callback) { }; getSongs(function() { - soundcloud.cacheTracks(false, function(err) { + soundcloud.cacheTracks(true, function(err) { if (err) { callback(err); return; @@ -101,7 +101,7 @@ module.exports.getLatestSongsByTag = function(tag, count, callback) { }; getSongs(function() { - soundcloud.cacheTracks(false, function(err) { + soundcloud.cacheTracks(true, function(err) { if (err) { callback(err); return; @@ -144,7 +144,7 @@ module.exports.getTags = function(callback) { }; getCategories(function() { - soundcloud.cacheTracks(false, function(err) { + soundcloud.cacheTracks(true, function(err) { if (err) { callback(err); return; @@ -185,7 +185,7 @@ module.exports.getSongsByTag = function(tag, callback) { }; getSongs(function() { - soundcloud.cacheTracks(false, function(err) { + soundcloud.cacheTracks(true, function(err) { if (err) { callback(err); return; @@ -242,7 +242,7 @@ module.exports.getSongByUrl = function(url, callback) { }; getSongFromUrl(url, getSong, function() { - soundcloud.cacheTracks(false, function(err) { + soundcloud.cacheTracks(true, function(err) { if (err) { callback(err); return; @@ -304,7 +304,7 @@ module.exports.getCommentsByUrl = function(url, callback) { }; getSongFromUrl(url, getComments, function() { - soundcloud.cacheTracks(false, function(err) { + soundcloud.cacheTracks(true, function(err) { if (err) { callback(err); return; @@ -376,7 +376,7 @@ module.exports.postComment = function(userId, url, content, callback) { }; getSongFromUrl(url, resolve, function() { - soundcloud.cacheTracks(false, function(err) { + soundcloud.cacheTracks(true, function(err) { if (err) { callback(err); return;