From 90ad278588b7600828ad9ba3e048abd05dd8e171 Mon Sep 17 00:00:00 2001 From: Darius Kazemi Date: Mon, 15 Oct 2018 11:46:18 -0700 Subject: [PATCH] Fix bug in JSON parsing when fetching from DB --- routes/user.js | 9 +++++---- routes/webfinger.js | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/routes/user.js b/routes/user.js index 01cecb4..080f735 100644 --- a/routes/user.js +++ b/routes/user.js @@ -16,10 +16,10 @@ router.get('/:name', function (req, res) { return res.status(404).json(`No record found for ${name}.`); } else if (req.headers.accept.includes('application/activity+json') || req.headers.accept.includes('application/json') || req.headers.accept.includes('application/json+ld')) { - res.json(result.actor); + res.json(JSON.parse(result.actor)); } else { - let actor = result.actor; + let actor = JSON.parse(result.actor); let username = name.replace('@'+domain,''); console.log(username, actor); let content = db.prepare('select content from feeds where username = ?').get(username); @@ -29,9 +29,10 @@ router.get('/:name', function (req, res) { let feedData = JSON.parse(content.content); let imageUrl = null; // if image exists set image - if (feedData.image && feedData.image.url) { - imageUrl = feedData.image.url; + if (actor.icon && actor.icon.url) { + imageUrl = actor.icon.url; } + console.log(actor, imageUrl); res.render('user', { displayName: actor.name, items: feedData.items, accountName: '@'+name, imageUrl: imageUrl }); } } diff --git a/routes/webfinger.js b/routes/webfinger.js index c66594c..c743d84 100644 --- a/routes/webfinger.js +++ b/routes/webfinger.js @@ -15,7 +15,7 @@ router.get('/', function (req, res) { return res.status(404).send(`No record found for ${name}.`); } else { - res.json(result.webfinger); + res.json(JSON.parse(result.webfinger)); } } });