-
-
Save newz2000/378e2308f9c12a12ed77 to your computer and use it in GitHub Desktop.
Post route
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
router.post('/', function(req, res) { | |
readLink(req.param('link'), function(err, summary) { | |
if(err) { | |
res.status(400); | |
res.send('Failed to fetch link: '+req.param('link')); | |
return; | |
} | |
new Link({ | |
url: req.param('link'), | |
_creator: req.user._id, | |
title: summary.title, | |
image: summary.image, | |
sentiment: summary.sentiment, | |
keywords: summary.topics, | |
words: summary.words, | |
difficulty: summary.difficulty, | |
readingTime: summary.minutes | |
}).save(function(err, link, count) { | |
if(err) { | |
res.status(400); | |
res.render('error', { | |
message: 'Could not save link', | |
error: err | |
}) | |
return | |
} | |
res.redirect('/links/'+link._id); | |
}) | |
}); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment