|
@@ -1,17 +1,7 @@
|
|
|
-/* eslint-disable
|
|
|
|
|
- no-return-assign,
|
|
|
|
|
-*/
|
|
|
|
|
-// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
|
-// Fix any style issues and re-enable lint.
|
|
|
|
|
-/*
|
|
|
|
|
- * decaffeinate suggestions:
|
|
|
|
|
- * DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
|
- * DS207: Consider shorter variations of null checks
|
|
|
|
|
- * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
|
- */
|
|
|
|
|
let MockWebApi
|
|
let MockWebApi
|
|
|
const express = require('express')
|
|
const express = require('express')
|
|
|
const bodyParser = require('body-parser')
|
|
const bodyParser = require('body-parser')
|
|
|
|
|
+const { expressify } = require('@overleaf/promise-utils')
|
|
|
const app = express()
|
|
const app = express()
|
|
|
const MAX_REQUEST_SIZE = 2 * (2 * 1024 * 1024 + 64 * 1024)
|
|
const MAX_REQUEST_SIZE = 2 * (2 * 1024 * 1024 + 64 * 1024)
|
|
|
|
|
|
|
@@ -33,19 +23,15 @@ module.exports = MockWebApi = {
|
|
|
return (this.docs[`${projectId}:${docId}`] = doc)
|
|
return (this.docs[`${projectId}:${docId}`] = doc)
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
- setDocument(
|
|
|
|
|
|
|
+ async setDocument(
|
|
|
projectId,
|
|
projectId,
|
|
|
docId,
|
|
docId,
|
|
|
lines,
|
|
lines,
|
|
|
version,
|
|
version,
|
|
|
ranges,
|
|
ranges,
|
|
|
lastUpdatedAt,
|
|
lastUpdatedAt,
|
|
|
- lastUpdatedBy,
|
|
|
|
|
- callback
|
|
|
|
|
|
|
+ lastUpdatedBy
|
|
|
) {
|
|
) {
|
|
|
- if (callback == null) {
|
|
|
|
|
- callback = function () {}
|
|
|
|
|
- }
|
|
|
|
|
const doc =
|
|
const doc =
|
|
|
this.docs[`${projectId}:${docId}`] ||
|
|
this.docs[`${projectId}:${docId}`] ||
|
|
|
(this.docs[`${projectId}:${docId}`] = {})
|
|
(this.docs[`${projectId}:${docId}`] = {})
|
|
@@ -55,54 +41,51 @@ module.exports = MockWebApi = {
|
|
|
doc.pathname = '/a/b/c.tex'
|
|
doc.pathname = '/a/b/c.tex'
|
|
|
doc.lastUpdatedAt = lastUpdatedAt
|
|
doc.lastUpdatedAt = lastUpdatedAt
|
|
|
doc.lastUpdatedBy = lastUpdatedBy
|
|
doc.lastUpdatedBy = lastUpdatedBy
|
|
|
- return callback(null)
|
|
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
- getDocument(projectId, docId, callback) {
|
|
|
|
|
- if (callback == null) {
|
|
|
|
|
- callback = function () {}
|
|
|
|
|
- }
|
|
|
|
|
- return callback(null, this.docs[`${projectId}:${docId}`])
|
|
|
|
|
|
|
+ async getDocument(projectId, docId) {
|
|
|
|
|
+ return this.docs[`${projectId}:${docId}`]
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
run() {
|
|
run() {
|
|
|
- app.get('/project/:project_id/doc/:doc_id', (req, res, next) => {
|
|
|
|
|
- return this.getDocument(
|
|
|
|
|
- req.params.project_id,
|
|
|
|
|
- req.params.doc_id,
|
|
|
|
|
- (error, doc) => {
|
|
|
|
|
- if (error != null) {
|
|
|
|
|
- return res.sendStatus(500)
|
|
|
|
|
- } else if (doc != null) {
|
|
|
|
|
|
|
+ app.get(
|
|
|
|
|
+ '/project/:project_id/doc/:doc_id',
|
|
|
|
|
+ expressify(async (req, res, next) => {
|
|
|
|
|
+ try {
|
|
|
|
|
+ const doc = await this.getDocument(
|
|
|
|
|
+ req.params.project_id,
|
|
|
|
|
+ req.params.doc_id
|
|
|
|
|
+ )
|
|
|
|
|
+ if (doc != null) {
|
|
|
return res.send(JSON.stringify(doc))
|
|
return res.send(JSON.stringify(doc))
|
|
|
} else {
|
|
} else {
|
|
|
return res.sendStatus(404)
|
|
return res.sendStatus(404)
|
|
|
}
|
|
}
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ return res.sendStatus(500)
|
|
|
}
|
|
}
|
|
|
- )
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ })
|
|
|
|
|
+ )
|
|
|
|
|
|
|
|
app.post(
|
|
app.post(
|
|
|
'/project/:project_id/doc/:doc_id',
|
|
'/project/:project_id/doc/:doc_id',
|
|
|
bodyParser.json({ limit: MAX_REQUEST_SIZE }),
|
|
bodyParser.json({ limit: MAX_REQUEST_SIZE }),
|
|
|
- (req, res, next) => {
|
|
|
|
|
- return MockWebApi.setDocument(
|
|
|
|
|
- req.params.project_id,
|
|
|
|
|
- req.params.doc_id,
|
|
|
|
|
- req.body.lines,
|
|
|
|
|
- req.body.version,
|
|
|
|
|
- req.body.ranges,
|
|
|
|
|
- req.body.lastUpdatedAt,
|
|
|
|
|
- req.body.lastUpdatedBy,
|
|
|
|
|
- error => {
|
|
|
|
|
- if (error != null) {
|
|
|
|
|
- return res.sendStatus(500)
|
|
|
|
|
- } else {
|
|
|
|
|
- return res.json({ rev: '123' })
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- )
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ expressify(async (req, res, next) => {
|
|
|
|
|
+ try {
|
|
|
|
|
+ await MockWebApi.setDocument(
|
|
|
|
|
+ req.params.project_id,
|
|
|
|
|
+ req.params.doc_id,
|
|
|
|
|
+ req.body.lines,
|
|
|
|
|
+ req.body.version,
|
|
|
|
|
+ req.body.ranges,
|
|
|
|
|
+ req.body.lastUpdatedAt,
|
|
|
|
|
+ req.body.lastUpdatedBy
|
|
|
|
|
+ )
|
|
|
|
|
+ return res.json({ rev: '123' })
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ return res.sendStatus(500)
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
return app
|
|
return app
|