2014-02-12 10:23:40 +00:00
|
|
|
request = require("request")
|
|
|
|
settings = require("settings-sharelatex")
|
|
|
|
logger = require("logger-sharelatex")
|
|
|
|
|
|
|
|
module.exports =
|
|
|
|
|
|
|
|
publish : (user_id, project_id, callback)->
|
|
|
|
url = buildUrl(user_id, project_id)
|
|
|
|
request.post url, (err)->
|
|
|
|
if err?
|
|
|
|
logger.err err:err, "something went wrong publishing project as template"
|
|
|
|
callback err
|
|
|
|
|
|
|
|
unpublish: (user_id, project_id, callback)->
|
|
|
|
url = buildUrl(user_id, project_id)
|
|
|
|
request.del url, (err)->
|
|
|
|
callback()
|
|
|
|
|
|
|
|
|
2014-02-27 17:35:35 +00:00
|
|
|
getTemplateDetails: (user_id, project_id, callback)->
|
|
|
|
url = buildUrl(user_id, project_id)+"/details"
|
|
|
|
request.get url, (err, res, body)->
|
2014-03-20 12:53:23 +00:00
|
|
|
if err?
|
|
|
|
logger.err err:err, user_id:user_id, project_id:project_id, body:body, "error getting template details"
|
|
|
|
return callback err
|
2014-02-27 17:35:35 +00:00
|
|
|
try
|
|
|
|
json = JSON.parse body
|
|
|
|
catch err
|
2014-03-20 12:53:23 +00:00
|
|
|
logger.err err:err, user_id:user_id, project_id:project_id, body:body, "error parsing project json details"
|
2014-02-27 17:35:35 +00:00
|
|
|
return callback err
|
2014-03-20 12:53:23 +00:00
|
|
|
logger.log json:json, user_id:user_id, project_id:project_id, "got template details"
|
2014-02-27 17:35:35 +00:00
|
|
|
callback(err, json)
|
|
|
|
|
|
|
|
|
2014-02-12 10:23:40 +00:00
|
|
|
buildUrl = (user_id, project_id)->
|
2014-03-20 12:53:23 +00:00
|
|
|
url = "#{settings.apis.templates_api.url}/templates/user/#{user_id}/project/#{project_id}"
|