2018-03-22 05:49:12 -04:00
|
|
|
express = require("express")
|
|
|
|
app = express()
|
|
|
|
bodyParser = require('body-parser')
|
|
|
|
|
|
|
|
app.use(bodyParser.json())
|
|
|
|
|
|
|
|
module.exports = MockV1Api =
|
2018-05-16 11:31:28 -04:00
|
|
|
users: { }
|
|
|
|
|
|
|
|
setUser: (id, user) ->
|
|
|
|
@users[id] = user
|
2018-03-22 05:49:12 -04:00
|
|
|
|
|
|
|
exportId: null
|
|
|
|
|
|
|
|
exportParams: null
|
|
|
|
|
|
|
|
setExportId: (id) ->
|
|
|
|
@exportId = id
|
|
|
|
|
|
|
|
getLastExportParams: () ->
|
|
|
|
@exportParams
|
|
|
|
|
|
|
|
clearExportParams: () ->
|
|
|
|
@exportParams = null
|
|
|
|
|
|
|
|
run: () ->
|
2018-05-16 11:31:28 -04:00
|
|
|
app.get "/api/v1/sharelatex/users/:ol_user_id/plan_code", (req, res, next) =>
|
|
|
|
user = @users[req.params.ol_user_id]
|
|
|
|
if user
|
|
|
|
res.json user
|
|
|
|
else
|
|
|
|
res.sendStatus 404
|
|
|
|
|
2018-03-22 05:49:12 -04:00
|
|
|
app.post "/api/v1/sharelatex/exports", (req, res, next) =>
|
|
|
|
#{project, version, pathname}
|
|
|
|
@exportParams = Object.assign({}, req.body)
|
|
|
|
res.json exportId: @exportId
|
|
|
|
|
|
|
|
app.listen 5000, (error) ->
|
|
|
|
throw error if error?
|
|
|
|
.on "error", (error) ->
|
2018-05-16 11:31:28 -04:00
|
|
|
console.error "error starting MockV1Api:", error.message
|
2018-03-22 05:49:12 -04:00
|
|
|
process.exit(1)
|
|
|
|
|
|
|
|
MockV1Api.run()
|