2016-11-11 12:03:01 -05:00
|
|
|
request = require "request"
|
|
|
|
settings = require "settings-sharelatex"
|
|
|
|
_ = require("underscore")
|
|
|
|
logger = require "logger-sharelatex"
|
|
|
|
|
|
|
|
module.exports = BlogHandler =
|
|
|
|
|
|
|
|
getLatestAnnouncements: (callback)->
|
|
|
|
blogUrl = "#{settings.apis.blog.url}/blog/latestannouncements.json"
|
|
|
|
opts =
|
|
|
|
url:blogUrl
|
|
|
|
json:true
|
2017-03-08 12:58:22 -05:00
|
|
|
timeout:1000
|
2016-11-11 12:03:01 -05:00
|
|
|
request.get opts, (err, res, announcements)->
|
|
|
|
if err?
|
|
|
|
return callback err
|
|
|
|
if res.statusCode != 200
|
|
|
|
return callback("blog announcement returned non 200")
|
|
|
|
logger.log announcementsLength: announcements?.length, "announcements returned"
|
|
|
|
announcements = _.map announcements, (announcement)->
|
|
|
|
announcement.date = new Date(announcement.date)
|
|
|
|
return announcement
|
|
|
|
callback(err, announcements)
|